0

I am writing a program in java to convert xlsx to csv file. I have 4 to 5 jar files which I set permanently in classpath using this-

vim ~/.bashrc
export CLASSPATH="/path/to/file1":"/path/to/file2":"${CLASSPATH}"

when I created the jar file of my program then again it stopped working and I was getting error

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/xssf/usermodel/XSSFWorkbook

Again it seems issue related to classpath. Now how to solve this ? Below are the jar files which I exported in classpath-

commons-logging-1.1.3.jar
dom4j-1.6.1.jar
json-lib-2.4-jdk15.jar
jxl.jar
poi-3.10-FINAL-20140208.jar
poi-excelant-3.10-FINAL-20140208.jar
poi-ooxml-3.10-FINAL-20140208.jar
poi-ooxml-schemas-3.10-FINAL-20140208.jar
poi-scratchpad-3.10-FINAL-20140208.jar
xbean-2.3.0.jar
  • You're more than likely still missing some jar files. Apache POI has other dependencies it needs to run. List your jar files here and someone can help. – tjg184 Apr 24 '14 at 12:59
  • Are you sure that the class that is not found is in one of your specified JAR files? – Jens Baitinger Apr 24 '14 at 13:00
  • Yeah I listed all the jar files in my questions. If it's not there then how my program is working if I run directly (without creating jar file) – Himanshu Matta Apr 24 '14 at 13:03
  • http://stackoverflow.com/questions/12357136/reference-jars-inside-a-jar – Jay Apr 24 '14 at 13:11

1 Answers1

0

The environment variable 'CLASSPATH' is independent of java runtime.

For indicate java classpath for your jar file, you are send as parameter. For example:

java -cp  -.;/path/to/file1:/path/to/file2 -jar YourApp.jar

Or, you can create a batch file and run with .bat file (win) or .sh file (linux). For example:

java -cp .;bin/* com.example.MainClass

Copy all jar files in bin directory included your application, and com.example.MainClass represent the complete name of your main class.

You will run your app with the batch file.

elomas
  • 11
  • 3