Results 1 to 10 of 10
- 02-03-2014, 12:27 PM #1
Member
- Join Date
- Feb 2014
- Posts
- 3
- Rep Power
- 0
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
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
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,
MarcinLast edited by marzu; 02-03-2014 at 12:49 PM.
- 02-03-2014, 01:06 PM #2
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 01:12 PM.
"It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013
- 02-03-2014, 02:08 PM #3
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
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
- 02-03-2014, 03:14 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 02-04-2014, 02:07 PM #5
Member
- Join Date
- Feb 2014
- Posts
- 3
- Rep Power
- 0
Re: NoClassDefFoundError for apache poi from CMD
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
- 02-04-2014, 02:35 PM #6
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: NoClassDefFoundError for apache poi from CMD
Do you have names? I'm going to add them to my shit list.
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 02:40 PM.
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 02-04-2014, 07:34 PM #7
Re: NoClassDefFoundError for apache poi from CMD
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
- 02-05-2014, 11:23 AM #8
Member
- Join Date
- Feb 2014
- Posts
- 3
- Rep Power
- 0
Re: NoClassDefFoundError for apache poi from CMD
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 ?
- 02-05-2014, 11:42 AM #9
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
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
- 02-05-2014, 12:40 PM #10
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 12:42 PM.
"It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013
Similar Threads
-
Getting NoClassDefFoundError
By swaralipi in forum New To JavaReplies: 4Last Post: 02-06-2013, 07:07 AM -
Servlet Exception: java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSF
By wonde in forum Apache POIReplies: 3Last Post: 06-28-2012, 01:33 PM -
java.lang.NoClassDefFoundError: org/apache/catalina/startup/Bootstrap
By rohant18 in forum EclipseReplies: 4Last Post: 12-07-2010, 11:34 PM -
Apache Axis2 is built on Apache AXIOM, a new high performance, pull-based XML object.
By anusoniaa in forum XMLReplies: 0Last Post: 11-15-2008, 08:29 AM
Bookmarks