Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java IntelliJ GUI设计器Maven可执行JAR导出_Java_Maven_Intellij Idea_Jar - Fatal编程技术网

Java IntelliJ GUI设计器Maven可执行JAR导出

Java IntelliJ GUI设计器Maven可执行JAR导出,java,maven,intellij-idea,jar,Java,Maven,Intellij Idea,Jar,我使用的是的GUI设计器和编译系统。当我通过answer构建可执行的JAR文件时,构建成功。但是,当通过命令java-jar MyApplication.jar启动时,它会抛出一个异常: Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null. at javax.swing.JRootPane.setContentPa

我使用的是的GUI设计器和编译系统。当我通过answer构建可执行的
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);
mvn install
当在
IntelliJ
中从源代码运行时,它工作正常,但是
Maven
似乎无法正确构建
JAR
文件。毕竟,IntelliJ通过链接到
.form
文件来保持
.java
源代码文件不受GUI代码的影响,从而发挥了“魔力”

我还发现了一个可能的解决方案,它涉及到在
pom.xml
文件中添加一个特殊的插件,该插件似乎支持
IntelliJ
的GUI设计器的构建。所以我再次运行了
mvn clean compile assembly:single
,它没有任何错误,但是没有任何更改

如果我执行
mvn部署
,插件将抛出以下错误:

[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>

4.0.0
groupId
我的申请
1.0-快照
公地郎
公地郎
2.6
org.jsoup
jsoup
1.8.3
公地io
公地io
2.4
通用验证器
通用验证器
1.4.0
maven汇编插件
com.example.MyApplication
威利广场酒店
带有依赖项的jar
org.apache.maven.plugins
maven编译器插件
3.3
1.8
1.8
org.codehaus.mojo
IdeSigner maven插件
1.0-beta-1
javac2
真的
真的
真的

怎么了?如何使用
Maven
结合
IntelliJ
的GUI设计器正确导出可执行的
JAR
文件?

这是因为Maven不知道如何编译用IntelliJ GUI设计器创建的GUI。这就是为什么您必须显式地指示IntelliJ生成它理解而Maven不理解的所有代码


要执行此操作,请转到设置并将生成GUI更改为值,以Java源文件。从现在起,IntelliJ将包括所有负责在类本身中设置UI的代码,所有外部工具(如Maven、Eclipse)都将正常工作。

我在使用IntelliJ IDEA 2017.1.5时遇到了同样的问题,但我能够使用
Maven
。我用更新的插件源代码创建了一个
GitHub
存储库

首先,克隆项目

ideausigner maven plugin master
文件夹中,运行
install intellij libs.sh
脚本将
intellij
库安装到本地maven存储库中:

./install-intellij-libs.sh <path to your IntelliJ directory>
然后通过运行以下程序安装新插件:

setContentPane(panel);
mvn install
现在,您已经完成了环境设置

在实际项目中,在
pom.xml
中编辑插件的版本,如下所示:

<version>1.0-beta-2-17.1.5</version>
1.0-beta-2-17.1.5
还要添加以下依赖项:

 <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>

com.intellij
javac2
最新的
com.intellij
表格
最新的
com.intellij
asm all
最新的

现在,使用UI designer表单进行构建应该可以正常工作。

我也遇到了同样的问题,但我认为我找到了一个更简单的解决方案:

  • 在IntelliJ中,进入
    文件->设置->编辑器->GUI设计器
    并执行以下设置:

    • 将UI生成为:Java源代码
    • 启用
      自动复制表单运行时类…
  • 将以下依赖项添加到yout maven
    pom.xml

    <dependency>
        <groupId>com.intellij</groupId>
        <artifactId>forms_rt</artifactId>
        <version>7.0.3</version>
    </dependency>
    
  • 这应该可以做到——至少对我来说是这样。
    请告诉我它是否也适用于您:-)

    我遇到了同样的问题。你解决了这个问题吗?@André:不确定,但最近我不再有这个问题了,所有的问题似乎都解决了,就像问题是lambda表达式一样。如果我删除应用程序中的所有lambda表达式,它将部署…@André:我也不使用lambda表达式…根据@André的评论,请参阅:我要感谢您和源代码的原始维护者为更新的IntelliJ版本提供了兼容性修复。在Windows8(希望是10)下编译之后,当使用IntellijGUI编辑器和maven-plugin.Works时,我能够再次使用lambdas。然而,一件奇怪的事情是,在运行
    mvn包之后,当您尝试使用IDE运行项目时,IntelliJ
    将抛出以下异常:
    线程“AWT-EventQueue-0”java.lang.NoClassDefFoundError:com/IntelliJ/uiDesigner/core/Spacer中的异常以及如何避免此异常?通过
    Build
    ->
    rebuildproject
    重建是一种修复方法,但是为什么插件会导致缺少类?