File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes jar issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "jar issues" Watch "jar issues" New topic

jar issues

Adrian Perry
Ranch Hand

Joined: Jul 21, 2005
Posts: 42
Hello fellow ranchers

I have this class file that is used to send mails. This file requires 2 jars, activation.jar and mail.jar. Both these jars are included in the classpath.
This classfile runs perfectly when i run from the cmd or from eclipse.

But my requirement is that i need to make a jar file of the classfile. I have taken all the required steps while creating the jar file.
I created a manifest.txt file and it has 2 entries, Main-Class and
Class-Path. I have created jars using both cmd and eclipse. When I run the jar file i get the error

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Authenticator

This error i get for both the jars i have created one through cmd and the other through eclipse. javax/mail/Authenticator
This class is there in mail.jar, that i have included in the classpath.

I dont know why i am getting this error. When i run this classfile through cmd it runs fine, but when i run the jar file, it gives me the above error.

Please comment.
Thanks in advance
[ November 08, 2008: Message edited by: Adrian Perry ]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46393
Where do you get javax.mail.Authenticator from? I can't find it in the API. It might be a J2EE class, in which case you would have to install J2EE.
Adrian Perry
Ranch Hand

Joined: Jul 21, 2005
Posts: 42
Hi Campbell,

javax.mail.Authenticator is right inside mail.jar file. It is lying inside mail package that is inside javax package.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

When you execute your command to run your JAR file are the mail.jar and activation.jar files in the same path? So if you did an ls/dir you would see


If not then your application won't load them in the classpath as it won't be able to find the JAR files.

GenRocket - Experts at Building Test Data
Adrian Perry
Ranch Hand

Joined: Jul 21, 2005
Posts: 42

Issue solved?

I knew it was something obvious. My jar could not see the other jars. The reason being, there is file called Manifest.txt, in which you specify 2 parameters, in case your jar file has a main class and the path of other jar files that are required to run the main jar file.


Main-Class: abc.XYZ
Class-Path: a.jar b.jar dir/c.jar

The error that i was making was that i was separating the jars using ";" and they have to separated using a "space".

This is what i was doing
Class-Path: a.jar;b.jar;dir/c.jar
This is what was supposed to be done
Class-Path: a.jar b.jar dir/c.jar

Once that was done, my main jar could see the other jars.

I agree. Here's the link:
subject: jar issues
It's not a secret anymore!