It runs fine in Intellij but JAR does not...
I've been working on a project for my school and it works fine in Intellij but when I tried to run the JAR it releases an exception.
C:\Users\la\Desktop>java -jar FirmadorFT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: okhttp3/RequestBody
at LoginPanel.<init>(LoginPanel.java:67)
at Main.main(Main.java:6)
Caused by: java.lang.ClassNotFoundException: okhttp3.RequestBody
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 2 more
C:\Users\la\Desktop>
I tried to apply almost every possible solution on this forum but nothing works.
Can someone give me a light?
Upload id: 2022_06_22_hyKoxfoF6JracrTqjTk5jB (file: FirmadorFT.zip)
请先登录再写评论。
You need to include okhttp3 library into the jar archive.
See the instructions at https://stackoverflow.com/a/42200519/8203759
Hello Konstantin. It is included, that's why it works on Intellij. Check attached image in case that i'm missing something.
When I run it into Intellij it works pretty nice and all okhttps funcions works just fine.
It is working in IntelliJ as the dependency is defined in "Modules | Dependencies". Artifacts window has nothing common with how the application work inside the IDE.
Check your MANIFEST file, maybe it could be needed to unpack the content of okhttp.jar, so the class could be found in FirmadorFT.jar's root
Hello Konstantin, Ok, after your reply so I understand that something can work on IDE, but not in JAR and that's "normal".
Here is my MANIFEST.MF.
I have built this project entirely from zero using intellij so I was guessing that it would handle this for me, but looks like not.
Can you give me some idea of what I need to add to MANIFEST.MF to get a functional JAR that works as it does in IDE?
Again, thank you for your time and help. I'm new in Java and Choose Intellij because many people describe it as the perfect IDE.
Either unpoack okhttp jar to root directory of your jar (https://i.imgur.com/q0zaONZ.png), or add okhttp jar files to classpath in manifest like that: `Class-Path: <okhttp jar filename>.jar`
See https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html for more info.
I'd recommend you to use Maven/Gradle to handle all the dependencies. It will be easier and automatically.
I extract all dependencies, then I add the Class-Paths to the manifests and nothing works. So sad. It works fine in IDE, but jar is completely unusable.
Please share a sample project zipped with .idea folder included.
Thanks for any light
Upload id: 2022_06_27_YbDVuReMpXUEpUhsg77yZx (file: FirmadorFT_123.zip)
Here is how the .jar could be built: https://youtu.be/NeXu3WPlYXU
Please note that it is not possible to unpack all the jar files to the main .jar, as you are using signed dependencies. See https://stackoverflow.com/questions/34855649/invalid-signature-file-digest-for-manifest-main-attributes-exception-while-tryin for details.