我使用IntelliJ IDEA
的GUI設計和Maven
作爲構建系統。當我通過this答案構建可執行文件JAR
時,構建成功。然而,它拋出通過命令java -jar MyApplication.jar
啓動時的異常:的IntelliJ GUI設計的Maven可執行的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設計器here的構建支持。所以我再次跑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>
有什麼不對?如何使用Maven
結合IntelliJ
的GUI設計器來正確導出可執行文件JAR
?
我遇到了同樣的問題。你解決了這個問題嗎? –
@André: 不知道,但最近我不再有這個問題,它一切似乎 – BullyWiiPlaza
看起來像問題是lambda表達式。如果我刪除我的應用程序中的所有lambda表達式,它將部署.... –