Sunday 15 January 2012

java - Working with Apache.POI and getting an error message only when running it from a JAR file -



java - Working with Apache.POI and getting an error message only when running it from a JAR file -

i using apache poi work xls spreadsheet file , generate docx word document. programme runs fine on own, error message when running jar.

here details. programme compiles with:

javac -classpath poi-3.10.1/*;poi-3.10.1/ooxml-lib/*;commons-io-2.4/*;commons-lang3-3.3.2/*;guava-libaries/*;miglayout-4.0/*;. reviewreport.java

the programme runs with:

java -classpath poi-3.10.1/*;poi-3.10.1/ooxml-lib/*;commons-io-2.4/*;commons-lang3-3.3.2/*;guava-libaries/*;miglayout-4.0/*;. reviewreport

i set manifest file:

manifest-version: 1.0 class-path: poi-3.10.1/*;poi-3.10.1/ooxml-lib/*;commons-io-2.4/*;commons-lang3-3.3.2/*;guava-libaries/*;miglayout-4.0/*;. main-class: reviewreport

(there blank line @ bottom of manifest file)

creating jar works with:

jar cfm reviewreport.jar manifest.mf *.class

i seek run programme jar command:

java -classpath poi-3.10.1/*;poi-3.10.1/ooxml-lib/*;commons-io-2.4/*;commons-lang3-3.3.2/*;guava-libaries/*;miglayout-4.0/*;. -jar reviewreport.jar

but instead of running, these error messages:

exception in thread "main" java.lang.noclassdeffounderror: org.apache.poi.openxm l4j.exceptions.invalidformatexception @ java.lang.j9vminternals.prepareclassimpl(native method) @ java.lang.j9vminternals.prepare(j9vminternals.java:430) @ java.lang.class.getmethod(class.java:1061) @ sun.launcher.launcherhelper.getmainmethod(launcherhelper.java:506) @ sun.launcher.launcherhelper.checkandloadmain(launcherhelper.java:498) caused by: java.lang.classnotfoundexception: org.apache.poi.openxml4j.exceptions .invalidformatexception @ java.net.urlclassloader.findclass(urlclassloader.java:665) @ java.lang.classloader.loadclasshelper(classloader.java:942) @ java.lang.classloader.loadclass(classloader.java:851) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:335) @ java.lang.classloader.loadclass(classloader.java:827) ... 5 more

i trying understand causes programme can run on own not able run jar, when utilize same classpath in building jar. after researching it seemed problem might due 1 of 2 things: (1) trying utilize poi's code handles xls , doc files on file xlsx or docx (or vice versa), or (2) class loader not finding invalidformatexception class during runtime.

i've looked @ both potential problems. (1), programme process xls spreadsheet. i've gone through code , believe correctly utilize hssf classes poi. programme creates docx word document. i've gone through code , believe correctly uses xwpf classes that.

for (2), when utilize verbose class feature discussed in article @ http://www.ibm.com/developerworks/java/library/j-dclp1/index.html, command run programme is:

java -dibm.cl.verbose=org.apache.poi.openxml4j.exceptions.invalidformatexception -classpath poi-3.10.1/*;poi-3.10.1/ooxml-lib/*;commons-io-2.4/*;commons-lang3-3.3.2/*;guava-libaries/*;miglayout-4.0/*;. reviewsearchreport

the scheme shows how class loader searches class in various locations. ends successful statement:

appclassloader found org/apache/poi/openxml4j/exceptions/invalidformatexception. class in \poi-3.10.1\poi-ooxml-3.10.1-20140818.jar appclassloader found org.apache.poi.openxml4j.exceptions.invalidformatexception

but different result when run jar. command

java -dibm.cl.verbose=org.apache.poi.openxml4j.exceptions.invalidformatexception -classpath poi-3.10.1/*;poi-3.10.1/ooxml-lib/*;commons-io-2.4/*;commons-lang3-3.3.2/*;guava-libaries/*;miglayout-4.0/*;. -jar reviewreport.jar

and here displays:

appclassloader attempting find org.apache.poi.openxml4j.exceptions.invalidfor matexception appclassloader using classpath c:\reviewreport.jar appclassloader not find org/apache/poi/openxml4j/exceptions/invalidformate xception.class in c:\reviewreport.jar appclassloader not find org.apache.poi.openxml4j.exceptions.invalidformate xception

can point me in proper direction? have class loader problem here or code in programme incorrectly poi (such classes docx beingness used on doc file, or ones xlsx beingness used on xls file)?

yes, gagravarr, discovered jar command doesn't utilize "-classpath" argument (although don't error if include in command line).

more importantly, class-path section of manifest.mf file uses space separate items instead of semi-colon (";") used separate items when using "-classpath" argument in javac statement.

i changed manifest.mf file separate items in class-path section , listed jars instead of relying on "poi-3.10.1/*" wildcard formatting.

java jar apache-poi

No comments:

Post a Comment