I can run my program outside of a jar file, but I want to deploy it and run it as a jar.
This command works for running the .class file:
java -classpath .;./libs/mail.jar;./libs/jcommon-1.0.16.jar;./libs/jfreechart-1.0.13.jar;./libs/jxl.jar;./libs/ojdbc5.jar gdsreports/ReportsDriver
This is how I package my jar file:
jar -cfvm GDSReports.jar GDSReports.mf gdsreports/* util/* libs/*
My manifest looks like this:
Manifest-Version: 1.0
Main-Class: gdsreports.ReportsDriver
Created-By: Me
This is how I run my jar:
java -classpath .;./libs/mail.jar;./libs/jcommon-1.0.16.jar;./libs/jfreechart-1.0.13.jar;./libs/jxl.jar;./libs/ojdbc5.jar;./util;./gdsreports -jar GDSReports.jar
However, run I run the jar file, it fails to load all the libraries. This is what it spits out:
Error loading configuration file: config/reportConfig
Error loading configuration file: config/gdsIds
Exception in thread "main" java.lang.NoClassDefFoundError: jxl/write/WriteException
at util.ReportConfig.setupReports(ReportConfig.java:197)
at util.ReportConfig.setup(ReportConfig.java:65)
at gdsreports.ReportsDriver.main(ReportsDriver.java:36)
Caused by: java.lang.ClassNotFoundException: jxl.write.WriteException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
This is the expected output:
Error loading configuration file: config/reportConfig
Error loading configuration file: config/gdsIds
-------------------------------------
Running TimingReport with parameters:
Filename: Reports/06-26-2012/TimingRptZL_06-26-2012.xls
Brand: ZL
Using production database: false
-------------------------------------
-------------------------------------
Exception in thread "main" java.lang.NullPointerException
at gdsreports.TimingReport.fillChartData(TimingReport.java:417)
at gdsreports.TimingReport.fillReport(TimingReport.java:238)
at gdsreports.TimingReport.run(TimingReport.java:131)
at gdsreports.ReportsDriver.main(ReportsDriver.java:40)
What am I doing wrong?
The -classpath argument (and the CLASSPATH environment variable) are ignored when you use the -jar argument.
If a jar file depends on other libraries, you have two choices:
Use the Class-Path header in your MANIFEST.MF file to call out the other jars, or
Unpack the other jars and include them in your jar.
Related
I got this error when running a maven built jar file:
I build my jar file using maven on NetBean, I able to run without issue on my Netbean, but when I run the jar file java -jar SimpleTestMQ-1.0-SNAPSHOT.jar this error happens:
Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/mq/MQEnvironment
at com.stee.simpletestmq.SimpleTestApp.main(SimpleTestApp.java:16)
Caused by: java.lang.ClassNotFoundException: com.ibm.mq.MQEnvironment
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:521)
... 1 more
i am new to maven, after running Maven with mvn clean package command.
it compiles the project into an executable jar.
i run the jar in the terminal and got this error:
$ java -jar create_pass_criteria-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/mprv/automation/core/exceptions/AutomationException
at Create_pass_criteria.Main.main(Main.java:23)
Caused by: java.lang.ClassNotFoundException: com.mprv.automation.core.exceptions.AutomationException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
i have a lot of jars that i use in my code by importing them.
how can i make the jar also include those jars?
is this what this error means?
appreciate any help,
thank you
Try it
Just add all the required libraries to the classpath when using java -jar target/PriseDeNotes-0.0.1-SNAPSHOT.jar with the --classpath argument.
I was able to create an executable using launch4j and it works fine on my machine. When I send it to someone to run on their windows machine they get the following error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: spark/TemplateEngine
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: spark.TemplateEngine
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Any thoughts?
This exception may also occur if your maven dependencies do not have <scope> set to compile time (default) and dependency jars are not available at compile time. For instance if maven dependencies have <scope>provided</scope> in your pom.xml compiler will assume that the JRE/environment will provide these dependency jars but when the sources are compiled and these dependencies are not found, this exception will be thrown.
For example - below may lead to this exception if spark-mllib_2.11 dependency is not found during compile time although they are added and there is no error during editing;
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-mllib_2.11</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>
I had this problem because my version of java that was as default was 9, and somehow Spark didn't recognize it. So I changed to version 8 and it worked. To change in linux :
sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
In your case you may want another version, so choose yours (to list the versions you have in your computer use the -l option).
Had to set relative paths in the class path so the executable could locate the jar files
i'm trying to export a runnable jar from eclipse, but this is the result:
Exception in thread "main" java.lang.NoClassDefFoundError: neg1
Caused by: java.lang.ClassNotFoundException: neg1
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
This is the manifest:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ itextpdf-5.4.3.jar itext-pdfa-5.4.3.jar itext-xtra
-5.4.3.jar
Class-Path: .
Rsrc-Main-Class: Negozio.Start
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
And this is how the files are packed into the jar:
http://i.stack.imgur.com/uXEaQ.png
Where Operazioni and Negozio are the my packages and the itext are the external library
Did you forget to include an external jar file?
You must have external jars that you did not include when you exported or were not put in your class path. Right click on your project Properties->Java Build Path and then ensure the "Libraries" tab is selected. Ensure the jars are added here.
I have created jar in the following folder usr/local/bin/niidle.jar and my MANIFEST.MF file is as follows:
Manifest-Version: 1.0
Main-Class: com.ensarm.niidle.web.scraper.NiidleScrapeManager
Class-Path: hector-0.6.0-17.jar
I verified that the file hector-0.6.0-17.jar is also present in the folder:
/Projects/EnwelibDatedOct13/Niidle/lib/hector-0.6.0-17.jar
I don't want to give full class-path name in MANIFEST.MF file, because I have to run this jar on another machine. So I gave only jar file name Class-Path=hector-0.6.0-17.jar in MANIFEST.MF file.
In spite of mentioning the Class-Path in MANIFEST.MF file, when I run this using command:
java -jar /usr/local/bin/niidle.jar arguments...
It is showing the error message:
--Exception in thread "main" java.lang.NoClassDefFoundError:
me/prettyprint/hector/api/Serializer
at
com.ensarm.niidle.web.scraper.NiidleScrapeManager.main(NiidleScrapeManager.java:21)
Caused by: java.lang.ClassNotFoundException:
me.prettyprint.hector.api.Serializer
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 1 more
Please give me a solution for this error message.
Class-Path is relative or absolute to the directory where your jar file is located.
so for your case you have to hector-0.6.0-17.jar to /usr/local/bin