添加所有依赖项,但 NoClassDefFoundError com/intellij/uiDesigner/core/GridLayoutManager

问题描述 投票:0回答:2

我在我的程序中使用 Swing GUI Form。在 IntelliJ IDEA 中一切正常,但是通过 Maven 打包后出现错误:

C:\Work\Idea\XLSConfigurdator 目标>java -jar xlsconfigurdator-parent-1.0.jar。线程“main”中的异常 java.lang.NoClassDefFoundError: com/intellij/uiDesign 呃/核心/GridLayoutManager 在 XLSCreator.$$$setupUI$$$(XLSCreator.java) 在 XLSCreator。(XLSCreator.java:24) 在 XLSCreator.main(XLSCreator.java:73) 引起:java.lang.ClassNotFoundException:com.intellij.uiDesigner.core.GridLa 青年经理 在 java.net.URLClassLoader.findClass(URLClassLoader.java:381) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:424) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) ...还有3个

C:\Work\Idea\XLSConfigurdator 目标>java -jar xlsconfigurdator-parent-1.0.jar 线程“main”中出现异常 java.lang.NoClassDefFoundError: com/intellij/uiDesign 呃/核心/GridLayoutManager 在 XLSCreator.$$$setupUI$$$(XLSCreator.java) 在 XLSCreator。(XLSCreator.java:24) 在 XLSCreator.main(XLSCreator.java:73) 引起:java.lang.ClassNotFoundException:com.intellij.uiDesigner.core.GridLa 青年经理 在 java.net.URLClassLoader.findClass(URLClassLoader.java:381) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:424) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) ...还有3个

“main”方法仅运行类的构造函数,构造函数通过 $$$setupUI$$$() 方法配置 GUI 表单(文件 - 设置 - 生成 GUI 到:Java 源代码)。

public static void main(String[] args) {
    new XLSCreator();

    sourceClass sc = new sourceClass();
    array = sc.readFromExcel(fileName);
}

public XLSCreator() {
    $$$setupUI$$$();
    setContentPane(rootPanel);
    setVisible(true);
    setSize(500, 200);
    setTitle("I'll save your mistakes");

    aceptButton.addActionListener(this);
**etc**
...
}

我阅读了有关此错误的所有主题,我将所有依赖项添加到 pom.xml 中(poi、poi-ooxml、swingx、forms_rt、ideauidesigner-maven-plugin、junit、forms、javac2)、所有需要的插件(maven-jar-plugin ,ideauidesigner-maven-plugin)但打包后 GridLayoutManager 仍然存在问题。

java maven intellij-idea
2个回答
0
投票

谢谢大家,你们是最棒的。

但是我忘记粘贴到 pom.xml maven-compiler-plugin 并配置它

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>      
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>XLSCreator</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

0
投票

使用 Gradle

对我来说,通过自定义“jar”任务打包包含所有依赖项的 jar 后问题就解决了(另请注意评论中的指导)

构建.gradle
dependencies {
    implementation 'org.apache.commons:commons-lang3:3.12.0'
    implementation 'com.intellij:forms_rt:7.0.3'
}

application {
    mainClass = 'gui.MainWindow'
}

jar {
    /**
     * In order to make it works, need to follow below steps:
     * 1. In IntelliJ Settings, go to Build, Execution, Deployment -> Build Tools -> Gradle,
     *    replace selection of "Build and run using" with "IntelliJ IDEA"
     * 2. In IntelliJ Settings, go to Editor -> GUI Designer, replace selection of "Generate GUI into" with "Java source code"
     * 3. Build the project, so it will generate in the MainWindow.java the additional methods like "$$$setupUI$$$()"
     * 4. Revert back the IntelliJ Settings to use "Gradle" for building the project (step 1)
     * 5. Now you can run build via gradle, it will generate compatible runnable jar
     *
     * Note: there steps are required because gradle build doesn't take care of GUI Designer generated code
     */
    duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
    manifest {
        attributes 'Main-Class': application.mainClass
    }

    from sourceSets.main.output

    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.