java.lang.ClassNotFoundException: org.mariadb.jdbc.Driver after ant build.xml - java

I am creating jar and trying to execute the jar but its giving
C:\Users\xyz\workspace\ACS-AD\target>java -jar ExtractADData.jar
Current dir:C:\Users\xyz\workspace\ACS-AD\target
java.lang.ClassNotFoundException: org.mariadb.jdbc.Driver
Search error: java.lang.NullPointerException
java.lang.NullPointerException
at com.ACSSUsers_Mariadb.truncateACSSADStage(Unknown Source)
at com.ExtractADData.main(Unknown Source)
Its because of referenced jar not adding while building jar, so can I give java -cp "jar" Extract.jar or is there any other way to avoid this .. like forming jar with all dependency jars ? If so how to add it in build.xml ?

Related

Question about java.lang.NoClassDefFoundError: quickfix/MessageStoreFactory

I have a problem when I run my Java application for a FIX application. I have added all the QuickFIX/J jars to build the FIX application. But when I run my jar I always get this error:
Application: TestMarketdataRequest
Exception in thread "main" java.lang.NoClassDefFoundError: quickfix/MessageStoreFactory
at com.dxtr.fastmatch.FastmatchMDRequest.<init>(FastmatchMDRequest.java:14)
at com.dxtr.fastmatch.FastmatchMDRequest.main(FastmatchMDRequest.java:19)
Caused by: java.lang.ClassNotFoundException: quickfix.MessageStoreFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 2 more
My question: How do I fix this and why do I get this error when I did add QuickFIX/J in my depedencies?
Include the dependency jar in your classpath when you run the main class using the -cp option:
java -cp quickfixj.jar MainClass
-classpath classpath
-cp classpath
Specifies a list of directories, JAR files, and ZIP archives to search for class files. Separate class path entries with semicolons (;). Specifying -classpath or -cp overrides any setting of the CLASSPATH environment variable.
More on the docs.
this is closed. i have add executable jar in my pom. so it is closed right now thanks all

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger after creating an executable JAR but this is a JAVA Project

I have a JAVA (awt) Project to build a desktop base utility. When I try to run this from other machine with only JRE Installed this is giving an exception as
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at DataProcessor.DataProcessor.App.<clinit>(App.java:73)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
here I am not using a maven project, creating an executable JAR directly from eclipse. All though I see the JAR for log4J (log4j-1.2.17.jar) in the MANIFEST. But this is giving an exception when I try to run it from other machines. ( Other machines has only JRE not JDK) following command I am using to run JAR
C:\Users\<username>\Desktop\Utility\latest>"C:\Program Files\Java\jre1.8.0_161\bin\java.exe" -jar Utility.jar
The exception is sayin' that you don't have the log4j dependency found on your class path: are you providing the log4j.jar in the same folder as the one in which your jar is placed?
It is not so easy to reference other jars when running an application as java -jar yourApp.jar ...
You can take a look to this post about this referencing a jar when running another one;
If you want to investigate about MANIFEST usage, take a look here;
However, i suggest you to use maven (or do it manually) exporting a fatjar with the needed dependencies packaged into (take a look to maven-assembler plugin or Eclipse runnable jar export options).

Batch file creation to run executable jar file with external library jar file

I developed simple java project and want to run this project using the batch file. how to include the external jar file in the batch file in order run the java project successfully.
Project Structure is given below,
Click here to find the Project Structure Screen shot
lanch.bat file contains
java -Xms512M -Xmx512M -jar selflearn.jar -o true
PAUSE
how to include the POdetail_for_tests.txt file and libs folder as a reference while programming execute.
when trying to run the project with above batch file the following error occurs
F:\java>java -Xms512M -Xmx512M -jar selflearn.jar -o true
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/poi/xssf/usermodel/XSSFWorkbook
at selflearn.txtFileToCSV.csvToXLSX(txtFileToCSV.java:57)
at selflearn.txtFileToCSV.main(txtFileToCSV.java:48)
Caused by: java.lang.ClassNotFoundException:
org.apache.poi.xssf.usermodel.XSSFWorkbook
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)
... 2 more
F:\java>PAUSE
Press any key to continue . . .
There is -cp (classpath) option to include dependent jars:
F:\java>java -Xms512M -Xmx512M -cp "libs/*" -jar selflearn.jar -o true
As per the project structure screenshot, it should be able to locate POdetail_for_tests.txt file.

ClassNotFound Exception while trying to run jar in unix server

I created a executable jar of my Java project I tested the jar and it is working as expected in windows but when i try run the same jar in Unix..
java jar my.jar
..it is throwing me the error below:
Exception in thread "main" java.lang.NoClassDefFoundError: jar
Caused by: java.lang.ClassNotFoundException: jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
How to overcome the above error?
It should be
java -jar my.jar
not the
java jar my.jar
See
java - the Java application launcher
In a runnable jar file , there will be a MANIFEST.MF inside the META-INF folder. Inside MANIFEST.MF there should be an entry Main-Class: com.myapp.MyMainClass . This will be created automatically if you using the jar command to make a runnable jar file.To be sure,unjar the jar and see if this entry is present.

Additional jar files for java.exe -jar

I run the following command:
C:\Projects\java -cp ./dependency.jar -jar ./dist/main.jar
Exception in thread "main" java.lang.NoClassDefFoundError: MyException
Caused by: java.lang.ClassNotFoundException: MyException
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)
Could not find the main class: Main. Program will exit.
MyException is inside dependency.jar. I also tried to replace -cp with -classpath. What do I do wrong?
The -cp options is ignored if you use -jar. If you need extra jar-files on the class-path, you should specify this in the Manifest of main.jar like this:
Class-Path: dependency.jar
(Then you can run your program using java -jar main.jar.)
Related questions:
When creating a jar file how do I retain the existing classpaths to other jar files?
Cannot find class even when jar file is in working directory
Jetty Classpath issues
problem related to MANIFEST.MF in jar
Have you tried specifying the class path in the windows environment variable CLASSPATH ?
specify your environment variable CLASSPATH and put the value of your JAVA_HOME\lib and (path to all your classes) and also include current directory by including (dot or period sign).

Categories