IntelliJ GUI 设计器 Maven 可执行 JAR 导出 [英] IntelliJ GUI Designer Maven Executable JAR Export

查看:24
本文介绍了IntelliJ GUI 设计器 Maven 可执行 JAR 导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 IntelliJ IDEA 的 GUI 设计器和 Maven 作为构建系统.当我通过 this 答案构建可执行的 JAR 文件时,构建成功.但是,它在通过命令 java -jar MyApplication.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)
...

受影响的代码行如下:

setContentPane(panel);

当在 IntelliJ 中从源代码运行时,它工作正常,但是 Maven 似乎没有正确构建 JAR 文件.毕竟,IntelliJ 通过链接到 .form 文件来使 .java 源代码文件与 GUI 代码保持干净.

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.

我还找到了一个可能的解决方案,它涉及向 pom.xml 文件添加一个特殊插件,该插件似乎为 IntelliJ 的 GUI 设计器 启用构建支持="https://stackoverflow.com/a/25877166/3764804">此处.所以我再次运行 mvn clean compile assembly:single,它没有任何错误但没有任何改变.

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.

如果我执行mvn deploy,插件会抛出以下错误:

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

这是我的 pom.xml:

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>

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

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

推荐答案

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

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.

首先,克隆项目.

ideauidesigner-maven-plugin-master 文件夹中,运行 install-intellij-libs.sh 脚本以安装 IntelliJ 库进入您的本地 Maven 存储库:

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>

这里还有一个用于 Windows 的批处理文件 (install-intellij-libs.bat):

Here is also a batch file (install-intellij-libs.bat) for Windows:

SET INTELLIJ_HOME=C:Program FilesJetBrainsIntelliJ IDEA 173.3188.16 REM Edit this to match your path!
CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%libjavac2.jar" -DgroupId=com.intellij -DartifactId=javac2 -Dversion=17.1.5 -Dpackaging=jar
CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%libasm-all.jar" -DgroupId=com.intellij -DartifactId=asm-all -Dversion=17.1.5 -Dpackaging=jar
CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%libforms_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.

在您的实际项目中,将 pom.xml 中的插件版本编辑为:

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

<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 设计器表单一起正常工作.

Now building should work correctly with UI designer forms.

这篇关于IntelliJ GUI 设计器 Maven 可执行 JAR 导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆