Intellij GUI设计师Maven可执行罐出口

发布于 2025-02-06 20:47:30 字数 5764 浏览 3 评论 0 原文

我正在使用 Intellij Idea 的GUI Designer和 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);

, 但是, maven 似乎无法正确构建 jar 文件。毕竟,Intellij通过链接到 .form 文件来保留 .java 源代码文件从GUI代码清洁清洁源。

我还找到了一个可能的解决方案,该解决方案涉及在 pom.xml 文件中添加特殊插件,该文件似乎可以为 Intellij 的GUI Designer 在这里。因此,我运行了 MVN CLEAS COMPILE组装:单再次没有任何错误,但是什么都没有改变。

如果我进行 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>

怎么了?我如何使用 maven Intellij 的GUI设计器正确导出可执行的 JAR 文件?

I'm using IntelliJ IDEA's GUI designer and Maven as build system. When I build the executable JAR file via this answer, the build succeeds. However, it throws an exception when launched via the command 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)
...

The affected code line is the following:

setContentPane(panel);

When ran from source in IntelliJ, it works fine however Maven doesn't seem to properly build the JAR file. After all, IntelliJ does "magic" by linking to a .form file for keeping .java source code files clean from GUI code.

I also found a possible solution which involves adding a special plugin to the pom.xml file that seems to enable build support for IntelliJ's GUI designer here. So I ran mvn clean compile assembly:single again, it didn't have any errors however nothing changed.

If I do a mvn deploy, the plugin throws the following error:

[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

Here is my 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>

What is wrong? How do I properly export an executable JAR file using Maven in combination with IntelliJ's GUI designer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

阳光下的泡沫是彩色的 2025-02-13 20:47:30

之所以发生这种情况,是因为Maven真的不知道如何使用Intellij GUI设计师编译GUI。这就是为什么您必须明确指示Intellij生成其理解的所有代码,而Maven则没有。

要这样做,请访问 gui Designer >将GUI生成对 Java源文件的值。从现在开始,Intellij将包括所有负责在类本身中设置UI的代码,以及所有外部工具(例如Maven,Eclipse)将正常工作。

That happens because Maven doesn't really know how to compile GUI created with IntelliJ GUI Designer. That's why you have to explicitly instruct IntelliJ to generate all the code it understands and Maven doesn't.

To do this go to GUI Designer settings and change the Generate GUI into value to Java Source files. From now on IntelliJ will include all the code responsible for setting UI up in the class itself and all the external tools, like Maven, Eclipse will work properly.

七七 2025-02-13 20:47:30

我使用 Intellij Idea 2017.1.5 有同样的问题,但是我能够与 maven 一起使用。我创建了一个使用更新的插件源代码

首先,克隆项目。

indueUidesigner-maven-plugin-master 文件夹中,运行 install-intellij-libs.sh 脚本以安装 Intellij 库中的库中Maven存储库:

./install-intellij-libs.sh <path to your IntelliJ directory>

这也是Windows的批处理文件( install-Intellij-libs.bats.bat ):

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 Designer表单正确使用。

I had the same problem using IntelliJ IDEA 2017.1.5 but I was able to get it working with Maven. I created a GitHub repository with the updated plugin source code here.

First, clone the project.

In the ideauidesigner-maven-plugin-master folder, run the install-intellij-libs.sh script to install the IntelliJ libraries into your local maven repository:

./install-intellij-libs.sh <path to your IntelliJ directory>

Here is also a batch file (install-intellij-libs.bat) for 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

Then install your new plugin by running the following:

mvn install

Now you're done with setting up your environment.

In your actual project, edit the plugin's version in your pom.xml to this:

<version>1.0-beta-2-17.1.5</version>

Also add the following dependencies:

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

Now building should work correctly with UI designer forms.

窝囊感情。 2025-02-13 20:47:30

我遇到了同样的问题,但我认为我发现了一个更容易的解决方案:

  1. 在Intellij中进入 file-&gt;设置 - &GT;编辑 - &GT; GUI设计师进行以下设置:

    • 将UI生成:Java源代码
    • 启用自动复制表单运行时类...
  2. 将以下依赖性添加到yout maven pom中。 XML

     &lt; depentency&gt;
        &lt; groupid&gt; com.intellij&lt;/groupid&gt;
        &lt; artifactid&gt; forms_rt&lt;/artifactid&gt;
        &lt;版本&gt; 7.0.3&lt;/version&gt;
    &lt;/depentency&gt;
     
  3. 附加添加到您的 pom.xml 一个汇编插件片段,看起来像以下示例:

     &lt; build&gt;
            &lt;插件&gt;
                &lt;插件&gt;
                    &lt; groupid&gt; org.apache.maven.plugins&lt;/groupid&gt;
                    &lt; artifactid&gt; maven-semembly-plugin&lt;/artifactid&gt;
                    &lt; excutions&gt;
                        &lt;执行&gt;
                            &lt; phass&gt; package&lt;/phase&gt;
                            &lt;目标&gt;
                                &lt;目标&lt;/goal&gt;
                            &lt;/目标&gt;
                            &lt;配置&gt;
                                &lt; dentname&gt; testuiclient&lt;/darrame&gt; gt; gt;
                                &lt; appendAssemblyId&gt; false&lt;/appendassemblyid&gt; gt;
                                &lt; Archive&gt;
                                    &lt; subtest&gt;
                                        &lt; mainclass&gt;
                                            my.personal.mainclass
                                        &lt;/mainclass&gt;
                                    &lt;/subtest&gt;
                                    &lt;明显
                                        &lt;多释放&gt; true&lt;/多释放&gt;
                                        &lt; class-path&gt;。&lt;/class-path&gt;
                                    &lt;/subtestentries&gt;
                                &lt;/archive&gt;
                                &lt; distriptorrefs&gt;
                                    &lt; discriptorref&gt; jar-with-with依赖性
                                &lt;/distriptorrefs&gt;
                            &lt;/configuration&gt;
                        &lt;/rececution&gt;
                    &lt;/excutions&gt;
                &lt;/plugin&gt;
            &lt;/插件&gt;
        &lt;/build&gt;
     

应该这样做 - 至少对我有用。
只要让我知道它是否对您有效:-)

I had the same problem but I think I found a much easier solution:

  1. In IntelliJ go into File -> Settings -> Editor -> GUI Designer and do the following setting:

    • Generate UI into: Java source code
    • Enable Automatically copy form runtime classes...
  2. Add the following dependncy into yout maven pom.xml:

    <dependency>
        <groupId>com.intellij</groupId>
        <artifactId>forms_rt</artifactId>
        <version>7.0.3</version>
    </dependency>
    
  3. Additionally add to your pom.xml an assembly plugin snippet which could look like this example:

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                            <configuration>
                                <finalName>testUiClient</finalName>
                                <appendAssemblyId>false</appendAssemblyId>
                                <archive>
                                    <manifest>
                                        <mainClass>
                                            my.personal.MainClass
                                        </mainClass>
                                    </manifest>
                                    <manifestEntries>
                                        <Multi-Release>true</Multi-Release>
                                        <Class-Path>.</Class-Path>
                                    </manifestEntries>
                                </archive>
                                <descriptorRefs>
                                    <descriptorRef>jar-with-dependencies</descriptorRef>
                                </descriptorRefs>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    

That should do it - it works at least for me.
Just let me know if it works also for you :-)

云裳 2025-02-13 20:47:30

答案 @jorichard可能会简化并变得友好 - 因此,不需要任何本地安装IDE,并且所有配置和依赖关系管理都不需要由Maven完成。

插件 org.codehaus.mojo:indueUidesigner-maven-plugin:1.0-beta-1 通过 com.intellij:javac2:7.0.3 com.intellij:forms_rt:7.0.3 (均在2008年最后更新)。从那以后,这些都没有直接更新,但是具有Jetbrains在

要做的就是覆盖插件依赖项。在此配置(对我有用)中,我在版本 212.5284.40 中更新到Jetbrains库,或者在撰写时最新的,与Intellij Ideas 2021.2.2相对应。

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>ideauidesigner-maven-plugin</artifactId>
            <version>1.0-beta-1</version>
            <dependencies>
                <dependency>
                    <groupId>com.jetbrains.intellij.java</groupId>
                    <artifactId>java-compiler-ant-tasks</artifactId>
                    <version>212.5284.40</version>
                </dependency>
                <dependency>
                    <groupId>com.jetbrains.intellij.java</groupId>
                    <artifactId>java-gui-forms-rt</artifactId>
                    <version>212.5284.40</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <goals>
                        <goal>javac2</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <fork>true</fork>
                <debug>true</debug>
                <failOnError>true</failOnError>
            </configuration>
        </plugin>
    </plugins>
</build>

<pluginRepositories>
    <pluginRepository>
        <id>intellij-repository</id>
        <url>https://www.jetbrains.com/intellij-repository/releases</url>
    </pluginRepository>
    <pluginRepository>
        <id>intellij-third-party</id>
        <url>https://cache-redirector.jetbrains.com/intellij-dependencies</url>
    </pluginRepository>
</pluginRepositories>

The answer by @jorichard may be simplifed and made CI friendly - so no local installation of any IDE is required and all configuration and dependency management is done by Maven.

The plugin org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1 has 2 dependencies on the code provided by Jetbrains via com.intellij:javac2:7.0.3 and com.intellij:forms_rt:7.0.3 (both last updated in 2008). These have not been directly updated since, but have modern equivalents hosted by Jetbrains in their own repositories.

All there is to be done is to overwrite the plugin dependencies. In this configuration (which is working for me) I updated to jetbrains libraries in version 212.5284.40, or latest at the time of writing, corresponding to Intellij IDEA 2021.2.2.

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>ideauidesigner-maven-plugin</artifactId>
            <version>1.0-beta-1</version>
            <dependencies>
                <dependency>
                    <groupId>com.jetbrains.intellij.java</groupId>
                    <artifactId>java-compiler-ant-tasks</artifactId>
                    <version>212.5284.40</version>
                </dependency>
                <dependency>
                    <groupId>com.jetbrains.intellij.java</groupId>
                    <artifactId>java-gui-forms-rt</artifactId>
                    <version>212.5284.40</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <goals>
                        <goal>javac2</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <fork>true</fork>
                <debug>true</debug>
                <failOnError>true</failOnError>
            </configuration>
        </plugin>
    </plugins>
</build>

<pluginRepositories>
    <pluginRepository>
        <id>intellij-repository</id>
        <url>https://www.jetbrains.com/intellij-repository/releases</url>
    </pluginRepository>
    <pluginRepository>
        <id>intellij-third-party</id>
        <url>https://cache-redirector.jetbrains.com/intellij-dependencies</url>
    </pluginRepository>
</pluginRepositories>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文