2

I'm developing a Java Swing application built on Gradle and I'm also using the IntelliJ GUI Form built-in Swing designer. I've decided to test if the executable jar created by Gradle works properly and the built application doesn't see the Swing components created by IntelliJ designer.

I've tried suggestions from: Intellij Idea 13 UI Designer and automatic Gradle building , but the jar still doesn't see those Swing components. I'm using IntelliJ Idea 2019.2. I've copied the 'forms_rt.jar' from my IntelliJ lib folder and linked it in the build.gradle file. I've also set IntelliJ GUI generation to Java code instead of binary code in the settings.

I created a 'lib' directory in my project and copied the 'forms_rt' jar there and renamed it to 'forms_rt-13.1.1.jar'. (I didn't change the version number for testing sake, although it should be 19.2 I think)

repositories {
    mavenCentral()
    flatDir dirs: "${rootDir}/lib"
}

jar {
    manifest {
        attributes 'Main-Class': 'aghwen.Main'
    }
}

dependencies {
    compile name: 'forms_rt', version: '13.1.1'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.json', name: 'json', version: '20180813'
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
}

I also added the jar to dependencies so it can properly link. In IntelliJ settings in Build, Execution, Deployment -> Build tools -> Gradle "Build and run using" and "Run tests using" are set to IntelliJ IDEA otherwise Java code would not be generated, but binary instead.

After testing every suggestion I've found on Stack and JetBrains forum I still can't make it run properly.

"C:\Program Files\Java\jdk1.8.0_211\bin\java.exe" -Dfile.encoding=windows-1252 -jar C:\Projects\Java\aghwen\build\libs\aghwen-5.0.jar
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/intellij/uiDesigner/core/GridLayoutManager
    at aghwen.ChoiceWindowForm.$$$setupUI$$$(ChoiceWindowForm.java:57)
    at aghwen.ChoiceWindowForm.<init>(ChoiceWindowForm.java:45)
    at aghwen.Main.lambda$main$0(Main.java:8)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: com.intellij.uiDesigner.core.GridLayoutManager
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 17 more

The jar doesn't have or doesn't see the generated Swing GUI and throws errors. What is interesting, if I remove the 'flatDir dirs: "${rootDir}/lib"' and 'compile name: 'forms_rt', version: '13.1.1' lines from build.gradle the jar won't be created as Gradle doesn't see the GUI components. That means Gradle knows about the forms library understands it, but it somehow doesn't link it in the jar created.

Answered:

I've found the answer here: intellij build jar artifact containing gradle dependencies Looks like my jar didn't include the forms_rt.jar needed to run created Swing components and the 'fatJar' task copied from above link made it all work fine.

0 Answers0