1

I'm trying to export my program as a runnable JAR, everything ran fine in Eclipse. I've checked the following:

  • Include all the jars in my Libraries under Java Build Path
  • Checked them all under Order and Export
  • When exporting, I selected Package required libraries into generated JAR
  • When I open the generated JAR, I can see all the other 3rd party JARs are in the root

However when I run my runnable JAR, I'm getting the following:

java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at ca.carillon.jnlp.Launcher.<clinit>(Launcher.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

The only other way I got my runnable JAR to work is to select Extract required libraries into generated JAR, however I don't want to extract all those 3rd party JARs, can someone tell me what else I'm missing in Eclipse?

codenamezero
  • 2,724
  • 29
  • 64

1 Answers1

0

In general there are three options:

  1. Create fat jar / uber jar - a jar file which has all required dependencies, not only to pass compilation, but also these required in runtime.
  2. Create "normal" jar with only your specific files and provide all required dependencies in classpath.
  3. Something in between: include some dependencies, provide some in classpath. (Though I'd consider this a bit odd.)

For such occasions I create fat jars with Gradle's Application plugin (https://docs.gradle.org/current/userguide/application_plugin.htm), Maven can also do that with (How can I create an executable JAR with dependencies using Maven?).

I'd recommend switching to some build tool anyway, as it will also run tests, etc. Creating a jar in IDE is IMHO rather bad idea, definitely not long term solution. Give Gradle a try. It's really simple.

Community
  • 1
  • 1
Piohen
  • 1,514
  • 15
  • 23