Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Priority

D

dushkin

Hello,

I built an eclipse project and used its Export tool to create a jar
file.
When I executed the jar, I got the above message.

The project folders structure is as follows:

/base/.settings
/base/config -->holds some xml file
/base/lib/ -->holds 3rd party jars including the log4j
/base/bin --> output folder. Also holds log4j.properties file.
/base/xxx --> holds the main class source
/base/src/a1/a2/a3/... --> sources
/base/src/b1/b2/b3/... --> sources
/base/src/c1/c2/c3/... --> sources

I wasted already so much time on that!
Any help will be blessed!

Thanks!
 
D

dushkin

And thus spoke dushkin...


Did you include that in your manifest?

Flo

This is the manifest file created automatically by the eclipse export
tool:

Manifest-Version: 1.0
Sealed: true
Main-Class: com.comverse.mep.CdrManagerNG.CdrManagerNG

Didn't think I need to change the auto created file...
And if so - do you think I need to add every jar to the manifest? And
how?
Thanks.
 
F

Flo 'Irian' Schaetz

And thus spoke dushkin...
Didn't think I need to change the auto created file...
And if so - do you think I need to add every jar to the manifest? And
how?

I'm no expert, but when I use Ant to build my files and create a .jar
(and .zip it toegether with the libs), I always add the class-path to
the manifest-file, for example:

Class-Path: . ./libs/MyLib.jar

With Ant it's rather simple to do that...

<manifest file="manifest.txt">
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="translator.Translator"/>
<attribute name="Class-Path" value=". ./libs/MyLib.jar"/>
</manifest>

Then I can use...

<jar destfile="${ant.project.name}.jar" basedir="${bin}"
manifest="manifest.txt"/>

....to create the jar with the correct manifest...

Flo
 
D

dushkin

And thus spoke dushkin...


I'm no expert, but when I use Ant to build my files and create a .jar
(and .zip it toegether with the libs), I always add the class-path to
the manifest-file, for example:

Class-Path: . ./libs/MyLib.jar

With Ant it's rather simple to do that...

<manifest file="manifest.txt">
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="translator.Translator"/>
<attribute name="Class-Path" value=". ./libs/MyLib.jar"/>
</manifest>

Then I can use...

<jar destfile="${ant.project.name}.jar" basedir="${bin}"
manifest="manifest.txt"/>

...to create the jar with the correct manifest...

Flo

Well, I added
Class-Path: ..\libs/lib\log4j-1.2.14.jar
to the manifest file but the result occur.

Any other ideas?
 
D

dushkin

Well, I added
Class-Path: ..\libs/lib\log4j-1.2.14.jar
to the manifest file but the result occur.

Any other ideas?- Hide quoted text -

- Show quoted text -

Well, I added
Class-Path: ..\libs\lib\log4j-1.2.14.jar
to the manifest file but the same result occur.

Any other ideas?
 
F

Flo 'Irian' Schaetz

And thus spoke dushkin...
Well, I added
Class-Path: ..\libs\lib\log4j-1.2.14.jar
to the manifest file but the same result occur.

above you write, that it's in /lib/, now you search for it in .
"../libs/lib/"...

MY directory is called "/libs/"... That isn't an integral part of the
line :) You have to put your own directory there...

In your case, probably...

Class-Path: . /lib/log4j-1.2.14.jar

Or perhaps /base/lib/etc. I'm not sure about your real structure.

Flo
 
D

dushkin

And thus spoke dushkin...


above you write, that it's in /lib/, now you search for it in .
"../libs/lib/"...

MY directory is called "/libs/"... That isn't an integral part of the
line :) You have to put your own directory there...

In your case, probably...

Class-Path: . /lib/log4j-1.2.14.jar

Or perhaps /base/lib/etc. I'm not sure about your real structure.

Flo

Hi Flo,
That was a foolish mistake developed from being so tired of seeking
for an answer... :-(

Anyway, it still no good...

Again:
The directories structure inside the jar is as follows:

/com --> contains sub folders with the class files
/config --> contains an xml file
/lib --> contains all the third party jars (including the log4j)
/Meta-inf
.classpath
.project

The manifest is:
---------------------
Manifest-Version: 1.0
Sealed: true
Main-Class: com.comverse.mep.CdrManagerNG.CdrManagerNG
Class-Path: .\lib\log4j-1.2.14.jar
---------------------
I also tried ..\lib and \lib

The classpath is

<?xml version="1.0" encoding="UTF-8" ?>
- <classpath>
<classpathentry kind="src" path="src" />
<classpathentry kind="lib" path="lib/log4j-1.2.14.jar" />
<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar" />
<classpathentry kind="lib" path="lib/jaxen-1.1-beta-5.jar" />
<classpathentry kind="lib" path="lib/sftp.jar" />
<classpathentry kind="lib" path="lib/classes12.jar" />
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER" />
<classpathentry kind="output" path="bin" />
</classpath>
 
L

Lew

Well, I added
Class-Path: ..\libs\lib\log4j-1.2.14.jar
to the manifest file but the same result occur.

Any other ideas?

Notice that Flo's example used forward slashes, not backslashes as yours did.
Also, you are rooting the log4j JAR's location in the parent directory of
your JAR, not usually safe, unlike Flo's example which used the current directory.

Notice that the log4j JAR must be located in a directory on the network / file
system where your JAR is, because:
The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols.

From
<http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html>
which you should read.
 
F

Flo 'Irian' Schaetz

And thus spoke Lew...
Notice that the log4j JAR must be located in a directory on the network / file
system where your JAR is, because:

Oh, f... yes. I knew I had forgotten something. My libs are in the
directory /libs/, not in the .jar file internal directory /libs/. So my
structure looks like this..

/MyJar.jar
/libs/MyLib1.jar
/libs/MyLib2.jar
etc.

The Manifest inside the MyJar.jar points to /libs/ in the filesystem...
This is why I use Ant .zip the whole thing after making the .jar, so I
bundle the libs and the jar toegether... (Ok, to be honest, I even use
an .exe wrapper, but that's what my boss wants - he forces me to do so :).

Flo
 
D

dushkin

Notice that Flo's example used forward slashes, not backslashes as yours did.
Also, you are rooting the log4j JAR's location in the parent directory of
your JAR, not usually safe, unlike Flo's example which used the current directory.

Notice that the log4j JAR must be located in a directory on the network / file
system where your JAR is, because:


From
<http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html>
which you should read.

Oh!
So, shouldn't (or maybe can't) the jars be placed inside the jar???
because this is how the export tool did by itself!
I would have prefered to ship a jar with all its resources inside...
How this information affects your kind advices Lew and Flo?
 
F

Flo 'Irian' Schaetz

And thus spoke dushkin...
So, shouldn't (or maybe can't) the jars be placed inside the jar???
because this is how the export tool did by itself!
I would have prefered to ship a jar with all its resources inside...
How this information affects your kind advices Lew and Flo?

Read the other posting: It's correct. To include another .jar into your
..jar, you'll probably have to extract the classes from it...

Flo
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top