NoClassDefFoundError thrown even when required class is present in classpath - java

Trying to run jar program and getting class not found error.
As shown in the figure, I have packaged all my dependent jar under lib folder and packaged it inside jar file.
Contents of lib directory:
In my manifest.mf file i have
Manifest-Version: 1.0
Class-Path: .\lib\arapi63.jar;.\lib\spring.jar;.\lib\commons-logging.j
ar;.\lib\log4j.jar;..\conf;.\lib\ojdbc14.jar
Created-By: 1.5.0_12 (Sun Microsystems Inc.)
Main-Class: RemedyRecord
when i try to run this jar using
java -jar remedyDSTX.jar
Exception in thread "main" java.lang.NoClassDefFoundError:
com/remedy/arsys/api/ARException
No ARException class is present in arapi63.jar which is present in my classpath and so am not sure why is that not referenced here...any thoughts?
Update:
Manifest-Version: 1.0
Class-Path: lib/arapi63.jar;lib/spring.jar;lib/commons-logging.jar;lib
/log4j.jar;lib/ojdbc14.jar
Created-By: 1.5.0_12 (Sun Microsystems Inc.)
Main-Class: RemedyRecord
I updated my manifest as per Jon's comment below but still am getting same error message.

I believe the problem is the format of your Class-Path entry.
As per the tutorial:
You specify classes to include in the Class-Path header field in the manifest file of an applet or application. The Class-Path header takes the following form:
Class-Path: jar1-name jar2-name directory-name/jar3-name
Note that this is space-separated, and uses a forward-slash between the directory name and the jar file name.
So try a Class-Path entry of:
Class-Path: lib/arapi63.jar lib/spring.jar lib/commons-logging.jar lib/log4j.jar lib/ojdbc14.jar
Note that I've removed the ../conf part - I don't believe you can add a directory to the classpath within a jar file manifest. (I've just tried, and it didn't work.)

Related

Eclipse Error: Could not find or load main class opencv

I keep getting these error every time I try to run the jar file I follow most of the questions that have been asked here haven't worked :(
and every time I export the jar file I got these warning
enter image description here
and this is my MANIFEST.MF
Manifest-Version: 1.0
Class-Path: .
Main-Class: gui_rec.Main
any suggestions?
Try to specify in your MANIFEST.MF classes to include in the Class-Path header field in the manifest file of an applet or application. The Class-Path header takes the following form:
Class-Path: jar1-name jar2-name directory-name/jar3-name
For more info go to link

Java manifest file altered after exporting project

This question is a follow up of this and this question. I've placed the META-INF/MANIFEST.MF file as suggested to /src/main/resources and exported the project using the following MANIFEST.MF file:
Manifest-Version: 1.0
Main-Class: org.fiware.kiara.generator.kiaragen
there is a new line after the Main-Class entry before the end of the file. The artifact configuration is bellow:
The MANIFEST.MF file in the .jar file is different from the one specified in the resources directory:
$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.5.0_13 (Apple Inc.)
Why is the Main-Class entry removed?
Simple - it is done due to the build cycle.
First your sorces gets compiled along with your manifest from the resources, second maven writes new manifest, and it gets simply overriden.
If you want to pust some custom stuff into your manifest, and you use Maven, you should rather modify your POM file to create proper manifest insteed of putting one in the resources.
Check following
https://maven.apache.org/shared/maven-archiver/examples/manifestFile.html for custom manifest includement.

How should my Java JAR main class path look like?

So I have Test.jar. It's directories look like:
META-INF/MANIFEST.MF
Test/src/test/Test.java
/MainFrame.java
/MainPanel.java
/image.png
And my mainfest file looks like:
Manifest-Version: 1.0
Created-By: 1.7.0_13 (Oracle Corporation)
Main-Class: test.Test
When launching from command line (java -jar Test.jar) i get such error: could not find or load main class test.Test. How to solve it? I know it's problem with Main-Class line in manifest but I dont know how should path look like..
thats because your jar apparently contains java source files and not compiled java class files.
your jar layout should be
META-INF/MANIFEST.MF
/test/Test.class
/MainFrame.class
/MainPanel.class
/image.png
your manifest is fine. you should compile your source code files (*.java) to produce *.class files and package those into your jar.

Java Main file not found

I'm trying to create a jar with the jar tool.
Using the following command
jar.exe cmfv manifest.txt lol.jar Main.class
This generates a jar with the following manifest:
Manifest-Version: 1.0
Created-By: 1.7.0_03 (Oracle Corporation)
Main-Class: Main
When I run the jar from command line (java -jar lol.jar) it runs fine. But when I double click the jar in my folder it gives an error: "Could not find the main class: Main.Program will exit."
What could be causing this?
After trying some stuff out the Manifest currently looks like this:
Manifest-Version: 1.0
Class-Path: .
Created-By: 1.7.0_03 (Oracle Corporation)
Main-Class: code.Main
The Main class has a package declaration added. Inside the jar the 'code' folder/package is added. Still have the same error though.
You should put your Main class into a package, and adjust your manifest correspondingly. That should solve the problem
You need to put the Main class in your classpath. When you run it from the command line, your current directory is auto-added to your classpath, this is why it works from there. When you double click it, you are not specifying the path to the jar as in the classpath. There are ways to add the class to your classpath in your manifest.
Below is an example of one of my jars. lib is a folder within the jar, com/sample/CommandLineClient.class is my main class.
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.5.0_12-b04 (Sun Microsystems Inc.)
Class-Path: lib/args4j-2.0.19.jar lib/axis.jar lib/axis-ant.jar lib/commons-discovery-0.2.jar lib/commons-logging-1.0.4.jar lib/jaxrpc.jar lib/log4j-1.2.8.jar lib/saaj.jar lib/wsdl4j-1.5.1.jar
Main-Class: com.sample.CommandLineClientSysIn
What is the file association with the .jar extensions?
Double click the jar file should make the jar run woth the javaw command.
Try making jar files to be executed by default with javaw.
Also take a look at this: http://www.wikihow.com/Run-a-.Jar-Java-File

Setting the Classpath in (Eclipse's) Jar File

I have a program.jar file which includes some external libraries. Additionally I wan't to start some classes with the program.jar.
The classes (TestKlass.class,...) are located in <path>/bin/data/test + sometimes there will be new classes added here.
How can I set this location for the classpath so I can use this command in the jar file:
cStart = Class.forName("data.test.TestKlass.class");
This is how my current MANIFEST.MF looks like:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ junit-4.10.jar selenium-java-2.20.0.jar WinRegistr
y-4.4.jar selenium-server.jar
Class-Path: .
Rsrc-Main-Class: data.Testworks
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
(Everything works fine within eclipse)
You can't reference external jars classes in a runnable jar file. Everything must be contained inside the jar.

Categories