Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By SurfMan

Thread: NoClassDefFoundError for apache poi from CMD

  1. #1
    marzu is offline Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    Question NoClassDefFoundError for apache poi from CMD

    Hi,

    I have donwloaded apache poi library (poi-bin-3.9-20121203.zip from Apache POI - Download Release Artifacts) and I have created simple project where I'm creating Workbook. When I'm launching project from the eclipse, everything is working fine. But when I'm trying to do that from CMD I'm receiving (for example) following errors:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unkno wn Source)
    Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 6 more
    This is what I have and still don't understand why it is not working:
    1) System: OS Windows 7, 64 bit
    2) Java: jdk1.5.0_20
    3) Environment variables: CLASSPATH is pointing to that:
    .;C:\PROGRA~2\IBM\SQLLIB\java\db2java.zip;C:\PROGR A~2\IBM\SQLLIB\java\db2jcc.jar
    ;C:\PROGRA~2\IBM\SQLLIB\java\db2jcc_license_cu.jar ;C:\PROGRA~2\IBM\SQLLIB\bin;C:
    \Program Files\Java\jdk1.6.0_45\lib;c:\Program Files (x86)\Java\jdk1.5.0_20\lib
    4) I have copied all jar files even to this location c:\Program Files (x86)\Java\jdk1.5.0_20\jre\lib\ext\
    5) In project I have those jar files in build path and class path

    Can anyone help me to solve that problem ? It is quite urgent for me because I have huge program which is generating advanced excel file. And only thing which is missing is running it from command line.

    Regards,
    Marcin
    Attached Files Attached Files
    Last edited by marzu; 02-03-2014 at 11:49 AM.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    986
    Rep Power
    2

    Default Re: NoClassDefFoundError for apache poi from CMD

    I don't see your classpath pointing to the POI jars.

    Edit: I didn't see you included them in "ext". But why? Why not just add them to the classpath like any other library? Just because you can, doesn't mean you should. In the 10+ years I am programming Java, I have never had the need of adding stuff to lib/ext. Dumping stuff in lib/ext just because you don't understand classpaths is a Bad Thing™.
    Last edited by SurfMan; 02-03-2014 at 12:12 PM.
    gimbal2 likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,087
    Rep Power
    6

    Default Re: NoClassDefFoundError for apache poi from CMD

    I really, really, really wonder what broken document is telling people to mess with the lib/ext folder.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: NoClassDefFoundError for apache poi from CMD

    Quote Originally Posted by gimbal2 View Post
    I really, really, really wonder what broken document is telling people to mess with the lib/ext folder.
    People who got sick and tired of explaining how the classpath variable works?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    marzu is offline Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    Default Re: NoClassDefFoundError for apache poi from CMD

    Quote Originally Posted by SurfMan View Post
    I don't see your classpath pointing to the POI jars.

    Edit: I didn't see you included them in "ext". But why? Why not just add them to the classpath like any other library? Just because you can, doesn't mean you should. In the 10+ years I am programming Java, I have never had the need of adding stuff to lib/ext. Dumping stuff in lib/ext just because you don't understand classpaths is a Bad Thing™.
    I thought that this is "New to Java" thread and not "Experienced in Java". That is why I have posted my question here. I have read only few articles how to build java project in eclipse and spent many hours trying to solve this error instead of asking. And beeing impolite is not helping anyone.
    I have added those jar files to jre\lib\ext\ directory to have them automatically in classpath. This is what I have found in the Internet. Maybe it is wrong or not. I don't know but was trying to solve it. But I was also thinking about having only 1 location for all 3rd party libraries (eg. in case for re-use it in other projects or making a backup of existing java installation).

    At least my colleague was able to help me.
    Instead of placing those jar files inside Java directory, I have added them to the project. So finally I have following list of jar files (apache poi, xbeans, ooxml-schemas-1.1.jar):
    commons-codec-1.5.jar
    commons-logging-1.1.jar
    dom4j-1.6.1.jar
    jsr173_1.0_api.jar
    junit-3.8.1.jar
    lista.txt
    log4j-1.2.13.jar
    ooxml-schemas-1.1.jar
    poi-3.9-20121203.jar
    poi-examples-3.9-20121203.jar
    poi-excelant-3.9-20121203.jar
    poi-ooxml-3.9-20121203.jar
    poi-ooxml-schemas-3.9-20121203.jar
    poi-scratchpad-3.9-20121203.jar
    resolver.jar
    xbean.jar
    xbean_xpath.jar
    xmlbeans-qname.jar
    xmlpublic.jar

    I have added them to Java Build Path and then exported whole project as a "Runnable JAR File" (selected "Copy required libraries ..." and "Save as ANT script").
    Finally, from the command line I have typed following commands:

    1) cd C:\Program Files (x86)\Java\jre1.5.0_20\bin

    2)
    C:\Program Files (x86)\Java\jre1.5.0_20\bin>java -jar "c:\Program Files (x86)\Eclipse\workspace\CRC\bin\CCRC.jar" -classpath . lib/poi-3.9-20121203.jar lib/commons-codec-1.5.jar lib/commons-logging-1.1.jar lib/junit-3.8.1.jar lib/log4j-1.2.13.jar lib/poi-ooxml-3.9-20121203.jar lib/poi-ooxml-schemas-3.9-20121203.jar lib/dom4j-1.6.1.jar lib/poi-examples-3.9-20121203.jar lib/poi-excelant-3.9-20121203.jar lib/poi-scratchpad-3.9-20121203.jar lib/jsr173_1.0_api.jar lib/resolver.jar lib/xbean_xpath.jar lib/xbean.jar lib/xmlbeans-qname.jar lib/xmlpublic.jar lib/ooxml-schemas-1.1.jar

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,087
    Rep Power
    6

    Default Re: NoClassDefFoundError for apache poi from CMD

    Quote Originally Posted by JosAH View Post
    People who got sick and tired of explaining how the classpath variable works?
    Do you have names? I'm going to add them to my shit list.

    Quote Originally Posted by marzu View Post
    I thought that this is "New to Java" thread and not "Experienced in Java". That is why I have posted my question here. I have read only few articles how to build java project in eclipse and spent many hours trying to solve this error instead of asking. And beeing impolite is not helping anyone.
    Assuming impoliteness is the most impolite thing you can do. There is nothing impolite about SurfMan's response, you're just making that up because it would be in your favor if it was. If you want to get help, don't alienate the people who are taking the time to respond to you.
    Last edited by gimbal2; 02-04-2014 at 01:40 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    986
    Rep Power
    2

    Default Re: NoClassDefFoundError for apache poi from CMD

    Quote Originally Posted by marzu View Post
    I thought that this is "New to Java" thread and not "Experienced in Java". That is why I have posted my question here. I have read only few articles how to build java project in eclipse and spent many hours trying to solve this error instead of asking. And beeing impolite is not helping anyone.
    I have added those jar files to jre\lib\ext\ directory to have them automatically in classpath. This is what I have found in the Internet. Maybe it is wrong or not. I don't know but was trying to solve it. But I was also thinking about having only 1 location for all 3rd party libraries (eg. in case for re-use it in other projects or making a backup of existing java installation).
    Obviously you haven't seen me being impolite. That looks very different than this. The internet is wrong. Setting up the classpath is something that is in the very first chapters of any Java tutorial. When you install Netbeans, you miss all that and suddenly "it doesn't work". It's fine that you skip those basic chapters, but don't call me impolite when I point that out.

    That last command line looks like something sensible. Glad you got it working.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  8. #8
    marzu is offline Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    Default Re: NoClassDefFoundError for apache poi from CMD

    Quote Originally Posted by SurfMan View Post
    Obviously you haven't seen me being impolite. That looks very different than this. The internet is wrong. Setting up the classpath is something that is in the very first chapters of any Java tutorial. When you install Netbeans, you miss all that and suddenly "it doesn't work". It's fine that you skip those basic chapters, but don't call me impolite when I point that out.

    That last command line looks like something sensible. Glad you got it working.
    Obviously I haven't seen you yet beeing impolite :D Apologize for that, but this is how I have interpreted your response. And after 2 weeks of struggling with this problem I was expecting a miracle (something like a guideline for a kid :D)
    Regarding classpath - I'm confused because: there is a environment variable called like that, in Eclipse there is classpath (under Run > Run configuration) and even people callin Java Build Path as a classpath. So for someone like me it is confusing (since I'm not a programmer any more and java is what I had only during the studies). And beeing forced to study whole apache poi library, then write a program (which will be building intermediate excel file) which will be a plugin for our solution is a quite big challenge.
    Anyway, above solutions was for Runnable JAR file (as I have pointed above) and it is not what we can use unfortunately :( I need to create JAR file but doing that I'm receiving NoClassDefFoundError.
    Can somone provide step by step solution for launching simple program, which is using apache poi library ?

  9. #9
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,087
    Rep Power
    6

    Default Re: NoClassDefFoundError for apache poi from CMD

    No I'm not going to do that, I want you to UNDERSTAND the basics of the tools you're using. I am not going to facilitate you jumping the gun, running before you can walk, cutting corners and just making your life a living hell.

    I wrote this article to help people like you make the right choice: start from the beginning, learn things step by step.

    I want to learn Java: 02. Getting dirty with the JDK tools

    Unfortunately I haven't gotten as far yet as to include working with libraries, because I reason that to be more advanced material to be covered when you have the basics of the basics in your head. Hopefully with this basic understanding of the tools you're supposed to know how to use, you can go ahead and puzzle out yourself what you need to do to to get your application up and running.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    986
    Rep Power
    2

    Default Re: NoClassDefFoundError for apache poi from CMD

    Why is a jar runnable? Because it contains a manifest that tells the full name of the class that contains the main method. So you could make a runnable jar by including a manifest with the line: Main-Class: com.mycompany.MyMainClass

    If you can't use a jar file with a manifest then you have add all the library jars to the classpath using -classpath, including your app's jar, then specify the main class as parameter on the commandline:
    java -classpath . "c:\Program Files (x86)\Eclipse\workspace\CRC\bin\CCRC.jar";/lib/poi-3.9-20121203.jar;lib/commons-codec-1.5.jar;xmlbeans-qname.jar;lib/xmlpublic.jar;...... com.mycompany.MyMainClass

    Note the ; separators between the jars (Should be a : on Linux)
    Last edited by SurfMan; 02-05-2014 at 11:42 AM.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Getting NoClassDefFoundError
    By swaralipi in forum New To Java
    Replies: 4
    Last Post: 02-06-2013, 06:07 AM
  2. Replies: 3
    Last Post: 06-28-2012, 12:33 PM
  3. Replies: 4
    Last Post: 12-07-2010, 10:34 PM
  4. Replies: 0
    Last Post: 11-15-2008, 07:29 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •