• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting an API to work right

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on a Java application that opens an .xls file reads the data and updates a database accordingly. To open the spreadsheet I'm using the POI API.

I have developped my application using Eclipse 3.0 and everything works properly in that environment. But once I make my executable jar I get NoClassDefFound errors when I try to open the .xls file. I have included the POI jar in my class path and when I leave it out my app errors out sooner than when I leave it in.

my command line looks like this: java -cp poi.jar; -jar myjar.jar

and the error looks like so

java.lang.NoClassDefFoundError: org/apache/poi/hssf/eventusermodel/HSSFListener
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)

Thanks in advance for you help

John Martinson
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel something wrong with class path, so its not finding the class.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use the -jar switch, the classpath (and the -cp switch) is ignored. Instead put the jar file on your classpath with -cp along with the POI jar, and start the program by naming the main class.
 
John Martinson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's the first good suggestion I've had on this problem yet.

I try java -classpath \lib\poi.jar;\myjar.jar testfram and no luck. I'm not sure about my syntax. I'ved tried lots of variations.

Thanks in advance.

John
 
John Martinson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is how it works, because I know people will search these later for an answer, I know I do

okay you make your jar file and then you go to the cammand line

and you type like so
java -cp c:\java\myjar.jar;c:\java\externaljar.jar; packagename/MainClass

I hope this will help someone in the future, because I had a doosy of a time figuring it out and no postings seemed to help until Ernest here posted his reply, thanks Ernest!

John (The one man programming show) Martinson
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just in case someone stumbles upon this in the future, John made a typo in his command. The package and class name should be seperated by a period, not a backslash.



The java command and the classpath are discussed in depth in the JDK Tools Documentation.
 
reply
    Bookmark Topic Watch Topic
  • New Topic