0

I used Eclipse Europa to develop my code . I am able to execute my code using eclipse. However i would like export my code as jar .

I have 4 classes in my project. I have used default package. My Class references external jars .

I tried to export as jar using export jar option . I donot have runnable jar option .

When i try to execute the program in command line it says

java -jar rus.jar "F2ile.xls" "Links.txt"

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/us
rmodel/RichTextString
        at ReadText.main(ReadText.java:29)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.RichTe
tString
        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)
        ... 1 more
nitishagar
  • 9,038
  • 3
  • 28
  • 40
user1710923
  • 35
  • 1
  • 8
  • 1
    Consider reading [Adding Classes to your JAR's Class Path](https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html) – Edwin Dalorzo Dec 19 '14 at 16:56
  • I am building jar using Eclipse. Not sure how to specify classpath – user1710923 Dec 19 '14 at 17:09
  • [Eclipse Europa](https://www.eclipse.org/europa/) was released in 2007. [Eclipse Luna](https://www.eclipse.org/luna/) was released in 2014. – Basilevs Dec 19 '14 at 17:27

2 Answers2

0

This is a classpath issue, you can try the following:

java -cp rus.jar:<poi-*.jar> <class> //poi jar name to provide and the class

Other option would be to use manifest file:

<jar jarfile="rus.jar">
    ..
    ..
    <manifest>
       <attribute name="Main-Class" value="<class_name>"/>
       <attribute name="Class-Path" value="<poi*.jar>"/>
    </manifest>
</jar>
nitishagar
  • 9,038
  • 3
  • 28
  • 40
0

Package your jar with a MANIFEST file in the META-INF directory (at root level in the jar file). In the MANIFEST add an entry to specify the main class to execute:
Main-Class: classname
where classname is the full class name including the package. When packaged you can run the main class with the command java -jar jarfile.jar.
You do not have to specify the class name on the command line. Easier for anybody that could use your jar file.

Olivier Meurice
  • 554
  • 8
  • 17