problem with MANIFEST.MF in jar - java

I have created my jar file in the following folder:
/usr/local/bin/niidle.jar
And I have one jarfile which is in the following folder
/Projects/EnwelibDatedOct13/Niidle/lib/hector-0.6.0-17.jar
And this file 'hector-0.6.0-17.jar' I have to include in MANIFEST.MF in jar.
And when I mention class path in MANIFEST.MF as follows:
Manifest-Version: 1.0
Main-Class: com.ensarm.niidle.web.scraper.NiidleScrapeManager
Class-Path: /Projects/EnwelibDatedOct13/Niidle/lib/hector-0.6.0-17.jar
When I run this using command:
java -jar /usr/local/bin/niidle.jar
It works properly..
But I dont want to give full Class-Path name, I have to give Class-Path as follows:
Manifest-Version: 1.0
Main-Class: com.ensarm.niidle.web.scraper.NiidleScrapeManager
Class-Path: lib/hector-0.6.0-17.jar
And when I run this using command:
java -jar /usr/local/bin/niidle.jar
It is showing 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 tell me solution for that...

I see at least two solutions:
store hector-0.6.0-17.jar inside niidle.jar and use a relative path in Class-Path. E.g. Class-Path: lib/hector-0.6.0-17.jar (for niidle.jar/lib/hector-0.6.0-17.jar)
java -cp /Projects/EnwelibDatedOct13/Niidle/lib/hector-0.6.0-17.jar -jar /usr/local/bin/niidle.jar

Create a lib folder in the folder where you are running the command, put hector-0.6.0-17.jar in it and try running the command again.

Related

(JAR file): java.lang.NoClassDefFoundError

I've little experience with Java and JAR files. I've downloaded a JAR file provided to me which seems to contain all of the necessary dependencies, but when I try to run java -jar MyJar.jar, it throws the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:420)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 3 more
The JAR file itself seems to contain all of the necessary dependencies as outlined in the MANIFEST.MF file:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ amqp-client-5.6.0.jar jackson-core-2.9.8.jar jacks
on-databind-2.9.8.jar jackson-annotations-2.9.0.jar jackson-dataforma
t-yaml-2.9.8.jar snakeyaml-1.23.jar slf4j-api-1.7.5.jar slf4j-log4j12
-1.7.5.jar log4j-1.2.17.jar httpclient-4.5.8.jar httpcore-4.4.11.jar
commons-logging-1.2.jar commons-codec-1.11.jar
Class-Path: .
Rsrc-Main-Class: TRECISExternalClient
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
I was wondering if there's something I'm missing or if it possible that something is malformed. Happy to provide more information if needed.
You can check below the link for complete implementation of the class org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
https://github.com/U-Alberta/exemplar/blob/master/src/org/eclipse/jdt/internal/jarinjarloader/JarRsrcLoader.java
Refer to line no 47 if (rsrcPath.endsWith("/")), I think you have to separate each jar with ./. Besides I see there is a blank space in this line after slash / in Rsrc-Class-Path: ./ amqp-client-5.6.0.jar. It should be Rsrc-Class-Path: ./amqp-client-5.6.0.jar. HttpClient is already available as per the image.
Turns out the issue wasn't with the JAR file itself but rather that I had multiple versions of OpenJDK on my system. Purging other versions and reinstalling OpenJDK v1.8.0 (openjdk-8-jdk on Ubuntu repos) solved the issue.

Hadoop jar execution failing on class not found

I am running my hadoop job and it is failing on class not found. 4 java files in total.
logProcessor.java
logMapper.java
logReducer.java
logParser.java
Everything is in a com folder on unix and I have "package com;" in the first line in all classes
that means if you do below command
head -5 *java
You will see
package com;
in all 4 files.
logProcessor is the Driver class. All files are in "com" folder on unix.
ls -ltr com/
logProcessor.java
logMapper.java
logReducer.java
logParser.java
I compiled the java program and made a jar out of it.
hadoop jar /var/lib/hadoop-hdfs/xxxx/jarFiles/LogParser.jar com.LogProcessor /user/hdfs/flume/2015-03-30/03 /user/xxxx/output_xxx
It gives me below error:
Exception in thread "main" java.lang.ClassNotFoundException: com.RFCLogProcessor
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.apache.hadoop.util.RunJar.main(RunJar.java:201)
First, you need to write your jar path in classpath. write directory path of your jar file into .bashrc file.
Then you can using below command:
hadoop jar directorypath/yourjarname.jar packagename.mainclassname outputpath
Everything that I was doing was right. Except that the classes which got created didnt have execute permission on them
So I did
chmod -R 777 com/
and jar'd it again and ran it with same above command and it executed.

Jar file with Jaudiotagger, NoClassDefFoundError

I made a java class using the library Jaudiotagger, and it runs without problems. I then made a jar out of it and I got NoClassDefFoundError. Here's how it went:
I put the main class id3tag.java and the library jaudiotagger-2.0.3.jar in a folder and compiled using the command line. The program ran smoothly without problems.
javac -cp .;jaudiotagger-2.0.3.jar id3tag.java
java -cp .;jaudiotagger-2.0.3.jar id3tag
I then created the manifest and the jar file.
echo Main-Class: id3tag >manifest.txt
jar cvfm id3tag.jar manifest.txt id3tag.class jaudiotagger-2.0.3.jar
I got the following output:
added manifest
adding: id3tag.class(in = 5952) (out= 2997)(deflated 49%)
adding: jaudiotagger-2.0.3.jar(in = 811441) (out= 740599)(deflated 8%)
I then ran the jar file, and got "A Java Exception has occurred.". I also tried:
java -jar id3tag.jar
And I got the output:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/tag/
FieldDataInvalidException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.tag.FieldDataInval
idException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more
I then replaced all (both) error classes used from Jaudiotagger with Exception and recreated the jar. Now the same thing happens as for seemingly all other jar files when I run them (with Java(TM) Platform SE binary, or through writing id3tag.jar in the command prompt) - nothing. java -jar, however, works and gave me a runtime error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/audi
o/AudioFileIO
at id3tag.tagSong(id3tag.java:112)
at id3tag.tagAlbum(id3tag.java:82)
at id3tag.tagArtist(id3tag.java:40)
at id3tag.main(id3tag.java:170)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.audio.AudioFileIO
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 4 more
It seems like the entire library just doesn't do shit for me. How do I fix this, and how do I get jar files to run without java -jar? (Also, how do I get the full pile'o'errors in case someone needs it, rather than just having it say "x more"?)
I'm not very savvy with this kinda shit so the more specific the answer, the better. Thanks.
I'm on windows 8 and latest java (1.7.0_17).
this is informing you that you have no main class, as you might or might not already know all programs in almost all non web based programming languages must have a main class to start from. In java it looks like this
public static int main(String[] args){
}
The message is informing you that this class is no longer there, this could be a compiler error or something entirely different.
please try downloading the library again, and downloading eclipse ide for java ee developers.
this ide has a built in compiler that will work better than a command line sometimes.
i hope this helped.
I worked around it by including the org folder from jaudiotagger in my .jar instead of the actual .jar file, and I then used a .bat file to run it instead of running the .jar directly. Feel free to add your own answer if you find a better solution, and I'll check back.
I extracted jaudiotagger-2.0.3.jar with winrar so that the org folder was in the same folder as my main class. Then I could compile and run the main class simply by:
javac id3tag.java
java id3tag
I then created the manifest file the same way as before, and created the jar:
jar cvfm id3tag.jar manifest.txt id3tag.class org
The jar file worked with java -jar id3tag.jar, but simply writing id3tag.jar still did nothing. Turns out it's because jar files are by default run by the javaw.exe file, so you have to right click the jar file -> open with -> choose default program and navigate to the java.exe file in your java folder (just search the folder). Running the .jar then gets you "Error: Could not find or load main class path\id3tag.jar". I worked around this by using a .bat file. I entered
java -jar path\id3tag.jar
into Notepad and saved as whatevername.bat (save as type: all files).
I created a new question for getting the .jar file to work properly. See .jar error - could not find or load main class.

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.

Java - Jar could not find included libraries and main class

I am currently trying to make a Jar with all my libraries included. What I have done, I have created folders like this :
eancopy (which contain all my classes)
lib (containing all my libraries : mongo, jedis...)
META-INF/MANIFEST.MF
My main class is named process (within the package eancopy)
My manifest is like this:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Class-Path: lib\commons-pool-1.5.6.jar lib\jedis-2.0.0.jar lib\mongo-2.6.3.jar
Created-By: 1.6.0_24-b07 (Sun Microsystems Inc.)
Main-Class: eancopy.process
I have generated the JAR with this command :
jar cvmf META-INF/MANIFEST.MF EANcopy.jar eancopy/*.class lib/*.jar
My problem : When executing the JAR by java -jar EANcopy.jar, it works when it is executed in the place where I have generated the JAR but in another place I have the message :
Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/DBObject
Caused by: java.lang.ClassNotFoundException: com.mongodb.DBObject
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: eancopy.process. Program will exit.
Any ideas ? Thanks
This exception shows you the cause of the problem:
Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/DBObject
You haven't specified these libs lib\commons-pool-1.5.6.jar lib\jedis-2.0.0.jar lib\mongo-2.6.3.jar in your CLASSPATH environment variable, hence why it fails when run in other places.

Categories