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

Discussion in 'Java' started by dushkin, Jul 12, 2007.

  1. dushkin

    dushkin Guest

    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!
     
    dushkin, Jul 12, 2007
    #1
    1. Advertising

  2. And thus spoke dushkin...

    > /base/lib/ -->holds 3rd party jars including the log4j


    Did you include that in your manifest?

    Flo
     
    Flo 'Irian' Schaetz, Jul 12, 2007
    #2
    1. Advertising

  3. dushkin

    dushkin Guest

    On Jul 12, 2:14 pm, Flo 'Irian' Schaetz <> wrote:
    > And thus spoke dushkin...
    >
    > > /base/lib/ -->holds 3rd party jars including the log4j

    >
    > 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.
     
    dushkin, Jul 12, 2007
    #3
  4. 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
     
    Flo 'Irian' Schaetz, Jul 12, 2007
    #4
  5. dushkin

    dushkin Guest

    On Jul 12, 3:08 pm, Flo 'Irian' Schaetz <> wrote:
    > 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


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

    Any other ideas?
     
    dushkin, Jul 12, 2007
    #5
  6. dushkin

    dushkin Guest

    On Jul 12, 4:05 pm, dushkin <> wrote:
    > On Jul 12, 3:08 pm, Flo 'Irian' Schaetz <> wrote:
    >
    >
    >
    >
    >
    > > 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

    >
    > 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?
     
    dushkin, Jul 12, 2007
    #6
  7. 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
     
    Flo 'Irian' Schaetz, Jul 12, 2007
    #7
  8. dushkin

    dushkin Guest

    On Jul 12, 4:15 pm, Flo 'Irian' Schaetz <> wrote:
    > 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


    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>
     
    dushkin, Jul 12, 2007
    #8
  9. dushkin

    Lew Guest

    Flo 'Irian' Schaetz wrote:
    >>> 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...


    dushkin wrote:
    > 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.

    --
    Lew
     
    Lew, Jul 12, 2007
    #9
  10. 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
     
    Flo 'Irian' Schaetz, Jul 12, 2007
    #10
  11. dushkin

    dushkin Guest

    On Jul 12, 4:40 pm, Lew <> wrote:
    > Flo 'Irian' Schaetz wrote:
    > >>> 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...

    > dushkin wrote:
    > > 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.
    >
    > --
    > Lew- Hide quoted text -
    >
    > - Show quoted text -


    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?
     
    dushkin, Jul 12, 2007
    #11
  12. 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
     
    Flo 'Irian' Schaetz, Jul 12, 2007
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page