IntelliJ GUI设计器Maven可执行JAR导出
我正在使用IntelliJ
IDEA
的GUI设计器和Maven
构建系统。JAR
通过此答案构建可执行文件时,构建成功。但是,通过命令启动时会引发异常java
-jar MyApplication.jar
:
Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null.
at javax.swing.JRootPane.setContentPane(JRootPane.java:621)
at javax.swing.JFrame.setContentPane(JFrame.java:698)
...
受影响的代码行如下:
setContentPane(panel);
当从中运行源代码时IntelliJ
,它可以正常运行,但是Maven
似乎无法正确构建JAR
文件。毕竟,IntelliJ通过链接到.form
文件来保持.java
源代码文件与GUI代码的一致,从而“神奇”
。
我还找到了一种可能的解决方案,其中涉及向pom.xml
文件添加一个特殊的插件,该插件似乎可以在此处启用对IntelliJ
GUI设计器的构建支持。所以我又跑了一次,它没有任何错误,但是没有任何变化。mvn
clean compile assembly:single
如果我执行mvn deploy
,则插件会引发以下错误:
[ERROR] Failed to execute goal org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1:javac2 (default) on project MyApplication: Execution default of goal org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1:javac2 failed: 16257 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
这是我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>MyApplication</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- Apache Commons Lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- Jsoup HTML parser -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
<!-- Apache Commons IO -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- Apache Commons Validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.MyApplication
</mainClass>
</manifest>
<manifestEntries>
<Built-By>BullyWiiPlaza</Built-By>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- IDEA Gui Designer Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>
怎么了?如何结合结合使用GUI设计器JAR
来正确导出可执行文件?Maven``IntelliJ
-
我在使用时遇到了同样的问题,
IntelliJ IDEA 2017.1.5
但可以使用Maven
。我在这里GitHub
用更新的插件源代码创建了一个存储库。首先,克隆项目。
在
ideauidesigner-maven-plugin-master
文件夹中,运行install-intellij- libs.sh
脚本以将IntelliJ
库安装到本地Maven存储库中:./install-intellij-libs.sh <path to your IntelliJ directory>
这也是
install-intellij-libs.bat
Windows 的批处理文件():SET INTELLIJ_HOME=C:\Program Files\JetBrains\IntelliJ IDEA 173.3188.16 REM Edit this to match your path! CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%\lib\javac2.jar" -DgroupId=com.intellij -DartifactId=javac2 -Dversion=17.1.5 -Dpackaging=jar CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%\lib\asm-all.jar" -DgroupId=com.intellij -DartifactId=asm-all -Dversion=17.1.5 -Dpackaging=jar CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%\lib\forms_rt.jar" -DgroupId=com.intellij -DartifactId=forms_rt -Dversion=17.1.5 -Dpackaging=jar
然后通过运行以下命令安装新插件:
mvn install
现在,您已经完成设置环境。
在您的实际项目中,将您的插件版本编辑为
pom.xml
:<version>1.0-beta-2-17.1.5</version>
还添加以下依赖项:
<dependency> <groupId>com.intellij</groupId> <artifactId>javac2</artifactId> <version>LATEST</version> </dependency> <dependency> <groupId>com.intellij</groupId> <artifactId>forms_rt</artifactId> <version>LATEST</version> </dependency> <dependency> <groupId>com.intellij</groupId> <artifactId>asm-all</artifactId> <version>LATEST</version> </dependency>
现在,构建应该可以与UI设计器表单正常工作。