-3

Possible Duplicate:
Easiest way to merge a release into one jar-file

I made a simple project with 4 classes. It uses the JDOM library and I included it in my classpath. When i make a JAR File, putting in 4 classes and a manifest, I get this error when I exec the JAR.

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jdom/JDOMException
    at Frame.setPeople(Frame.java:230)

It told me that JDOMException Class wasn't found. So, is there a trick to include an external library in a Jar file? If it's possible, could you give me an example about how to include the JDOM Library.

Community
  • 1
  • 1
REmaxer
  • 1
  • 3

3 Answers3

1

Hmmm... if you don't want to use ANT, I bet you won't want to use maven either. But this problem is not going to solve itself. You will have to do something. Anyhow...

Check out the maven shade plugin. You will have to switch your build environment to use maven, but once you do, the shade plugin can create an uber, executable jar with your code plus all your dependencies. See http://maven.apache.org/plugins/maven-shade-plugin/

Guido Simone
  • 7,912
  • 2
  • 19
  • 21
  • learning Maven is like learning how to create time for yourself it saves so much time in the long run. –  Oct 12 '12 at 19:44
  • I realized that these plugins/software make my work less hard.But i wanted to do it without any external Software. – REmaxer Oct 12 '12 at 19:53
  • External software exists to do these kinds of tasks for you. Why make life harder for yourself? – DNA Oct 12 '12 at 22:23
0
 java -cp pat/to/jdom.jar:path/to/my.jar my.main.JavaClass

Rolf

rolfl
  • 17,539
  • 7
  • 42
  • 76
0

You can probably do this by unpacking the contents of the JDOM library JAR using a tool such as Winzip, Archive Manager or similar, adding your classes, then re-compressing all the combined files into a new JAR.

A JAR is just a Zip archive, so many tools can decompress and compress them.

DNA
  • 42,007
  • 12
  • 107
  • 146