2

I have written a java program to convert input xml file into some other xml file. While doing this I am using excel file and for accessing xml file I used apache-poi libraries.

When I run my program in eclipse it works fine and gives required results. Now I export the project in jar file and I selected my main class while exporting into jar. But when I run the jar file, I am getting following exception:

D:\>java -jar EDR_to_DER_with_excel.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
    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)
Could not find the main class: com.unisys.xml.TestExcel. Program will exit.

The error is related to libraries that I am using. But I don't know why it's coming, because I am able to run the program in eclipse. Is the library class available in jar file> If not how can I give it to the jar while exporting?

4 Answers 4

2

It appears that the Apache POI Libraries are not in the classpath

Add the location of the libraries to PATH variable of your system (Assuming windows based on D:\ drive in question).

Sign up to request clarification or add additional context in comments.

1 Comment

If that's the folder that has all the dependent jars yes.
2

Export project do not included the external jars by default. You have to add the third party lib to the classpath:

java -cp <lips> -jar EDR_to_DER_with_excel.jar

Comments

0

I got the solution. I followed simple approach.

-> Right click on project 
-> Export 
-> as Runnable jar 
-> select radio button "Package required libraries into generated jar"
-> finish

This approach worked for me :)

Comments

0

I got the answer of the query in this case the jar files are missing in the program .Please check there are added from proper path. This worked for me

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.