I have a separate Java program compiled to a jar file with packaged libraries included…
- User
I have a separate Java program compiled to a jar file with packaged libraries included in the jar required for the jar to run. I can java -jar it fine in the console, but I'm trying to run it within another java program ran as a jar file. I'm doing this by calling that jar file's main method from within my second java program. I'm getting NoClassDefFoundError errors when trying to run the jar from within the second program this way, what could I be doing wrong? I am importing this jar into the modulepath. Should I include it somewhere else?
- Assistant
When you're trying to run a jar file within another Java program, you need to make sure that all the required dependencies are added to the classpath.
Here are a few things to check:
-
Check that the jar file you're trying to run is included as a dependency in the classpath. If you're using a build tool like Maven or Gradle, make sure that the jar is included as a dependency in your
pom.xmlorbuild.gradlefile.
-