executing jar : NoClassDefError

L

Leena

Hi,

I have made a jar file and I'm trying to execute the jar file, but it
gives me NoClassDefError. However, when I extract the jar file, I see
that class but, jar file in not able to find it.

The only different thing I'm doing is I've extracted another jar file
and added the content of that jar file in my jar. Since my project
needs to refer to another jar file, I had to extract the content of
that jar file and put it in my jar. This was suggested in previous
discussion.

Any suggestions, why jar is not able to find a class which I can see in
the jar?

Thanks,
Leena
 
A

Andrew Thompson

Leena wrote:
...
I have made a jar file and I'm trying to execute the jar file, but it
gives me NoClassDefError. .....
The only different thing I'm doing is I've extracted another jar file
and added the content of that jar file in my jar. ....

Other jars can be added to the classpath at runtime.
It is neither necessary, nor recommended, to 'rejar'
all resources into a single jar.
Any suggestions, why jar is not able to find a class which I can see in
the jar?

That probably depends a lot on the exact contents of the jar,
and the manifest file, neither of which we can see from here.
Why don't you upload the jar (how big is it?) to a free site and
let us have a look at it?

Andrew T.
 
L

Leena

Hi Andrew,

I found the problem!

I was wrongly creating the jar file. Even though my jar file had all
the class file, I was creating a folder and was storing classes of the
"available" jar file in that folder. So at runtime, since the classes
were inside folder(the one that I created) one level down, jar could
not find classes and throw error.

Less learnt: If the jar file is not working, then extract the jar file
and check the folder structure. This might give you the clue.

Thanks Andrew for your time,

Leena
 
N

Nigel Wade

Andrew said:
Leena wrote:
..

Other jars can be added to the classpath at runtime.

If it's a jar which is being executed via the -jar command line argument then
the classpath comes from the manifest of the specified jar, and can't be
modified at runtime. In this case the external jar needs to be added to the
classpath in the executable jar's manifest when it is built.
 
S

sayom88

Leena said:
Hi,

I have made a jar file and I'm trying to execute the jar file, but it
gives me NoClassDefError. However, when I extract the jar file, I see
that class but, jar file in not able to find it.

The only different thing I'm doing is I've extracted another jar file
and added the content of that jar file in my jar. Since my project
needs to refer to another jar file, I had to extract the content of
that jar file and put it in my jar. This was suggested in previous
discussion.

Any suggestions, why jar is not able to find a class which I can see in
the jar?

Thanks,
Leena
 
C

Carlus Henry

Nigel said:
If it's a jar which is being executed via the -jar command line argument then
the classpath comes from the manifest of the specified jar, and can't be
modified at runtime. In this case the external jar needs to be added to the
classpath in the executable jar's manifest when it is built.
I had a similar situation that may or may not help. I was building
entries in the MANIFEST.MF file through my ant build script. Well, what
I made a mistake and did was put a ":" at the end of my Built-By or some
other key value like that. It completely rendered my jar inoperable. I
got all kind of wacky strange errors.

Make sure that the MANIFEST.MF file is not breaking spec in some sort of
way.

Thanks
Carlus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top