I have built an java application that use Swing and Flatlaf as theme.
When I'm running the application through the IDE(InteliJ) it's running without any problem.
After I have built it succsesfully using the package
command from Maven, And when I try to run it I'm receiving this error:
(I get the same result if I build it through maven-jar-plugin:3.1.0
plugin)
Error: Unable to initialize main class com.Yad2AutomationWithGUI.bouncer.Main
Caused by: java.lang.NoClassDefFoundError: com/formdev/flatlaf/FlatDarculaLaf
I have understand that it's related to the JRE and JDK that installed on the PC, So I have updated them both to the latest version and also updated the env Path
for them.
C:\Users\USER>javac -version
javac 18.0.1.1
C:\Users\USER>java -version
java version "18.0.1.1" 2022-04-22
Java(TM) SE Runtime Environment (build 18.0.1.1 2-6)
Java HotSpot(TM) 64-Bit Server VM (build 18.0.1.1 2-6, mixed mode, sharing)
I have imported the Flatlaf
repository using Maven this way:
<dependencies>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>2.2</version>
</dependency>
....
</dependencies>
Thanks.
CodePudding user response:
This Exception Typically happens because It is not able to find .class file at runtime during program Execution. Sometimes, it also happens because Server Engine itself is corrupted in which case new server instance has to be used.
- Fix:
Replace the .class file manually in the deployment directory. Once .class files are found, it will run successfully. The perfect Fix for this is to write logic for autoDeployment = "true" in a Shell Script or Java class, where all classes(src and .class, target folder and other folders in webapp) are exploded and tested and validated in their directories and then autorun the webapplication to see if the webapplication works fine.
CodePudding user response:
Can you please verify if the flatlaf classes are included in the JAR file that you have built with Maven?
Edit: The comment of Thorbjørn sounds more reliable, I would recommend looking at the classpath as well.
Another option would be to build a 'fat' JAR containing all dependent classes as well. Look into the Maven Shade plugin for that.