Reputation: 41
SOLVED, I GOT IT TO WORK
I just completed my first real JAVA program. It is a program which lets you open a .xlsx file and the program extracts data from this file and shows this in a textArea.
In eclipse, the program works totally fine, but the exported jar doesn't. Once the project is exported I open it in CMD with java -jar c://...... and it opens just fine. However when I try to open the excel file I get this error:
So basically one of the needed .jar files seems not to be available in runtime. However I believe all of the needed poi-3.9 and xmlbeans are available. See this:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="src/xmlbeans-2.3.0.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-examples-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-excelant-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-ooxml-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-ooxml-schemas-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-scratchpad-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/log4j-1.2.13.jar"/>
<classpathentry exported="true" kind="lib" path="src/junit-3.8.1.jar"/>
<classpathentry exported="true" kind="lib" path="src/commons-logging-1.1.jar"/>
<classpathentry exported="true" kind="lib" path="commons-collections4-4.1-javadoc.jar"/>
<classpathentry exported="true" kind="lib" path="commons-collections4-4.1.jar"/>
<classpathentry exported="true" kind="lib" path="src/commons-codec-1.5.jar"/>
<classpathentry exported="true" kind="lib" path="poi-ooxml-3.9.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="lib/commons-codec-1.10.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-io-2.5.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-lang3-3.4.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/cssparser-0.9.20.jar"/>
<classpathentry exported="true" kind="lib" path="lib/htmlunit-2.23.jar"/>
<classpathentry exported="true" kind="lib" path="lib/htmlunit-core-js-2.23.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpclient-4.5.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpcore-4.4.4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpmime-4.5.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jetty-io-9.2.18.v20160721.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jetty-util-9.2.18.v20160721.jar"/>
<classpathentry exported="true" kind="lib" path="lib/neko-htmlunit-2.23.jar"/>
<classpathentry exported="true" kind="lib" path="lib/sac-1.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/serializer-2.7.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/websocket-api-9.2.18.v20160721.jar"/>
<classpathentry exported="true" kind="lib" path="lib/websocket-client-9.2.18.v20160721.jar"/>
<classpathentry exported="true" kind="lib" path="lib/websocket-common-9.2.18.v20160721.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xalan-2.7.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xercesImpl-2.11.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xml-apis-1.4.01.jar"/>
<classpathentry exported="true" kind="lib" path="src/jsoup-1.10.1.jar"/>
<classpathentry exported="true" kind="lib" path="src/dom4j-1.6.1.jar"/>
<classpathentry exported="true" kind="lib" path="src/selenium-server-standalone-3.0.1.jar"/>
<classpathentry exported="true" kind="lib" path="src/stax-api-1.0.1.jar"/>
<classpathentry kind="lib" path="src/poi-ooxml-3.11.jar"/>
<classpathentry exported="true" kind="lib" path="src/xbean-2.0.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
See also my Order and Exporttab in the build path configurations.
Am I missing something? Any help is greatly appreciated!
EDIT: I made some changes and all necessary jars are in the lib/ folder of my project. If I export jar and view the jar contents with: jar tf "location.jar". I get the following. So I believe this means that everything is exported nicely. Any suggestions on what might be going wrong, because i keep getting the same error.
Upvotes: 3
Views: 1741
Reputation: 10030
This is because eclipse reads your class-path dependencies and includes them in the runtime but for running the exported jar through the java -jar
command, you will have to add the -cp <your-jar-locations-semicolon-separated>
so that jvm knows that the jars are to be included in the class-path while execution.
alternatively, look into building a shaded jar which contains all your dependent jars in the exported jar.
Upvotes: 2