Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a Jar from other Jar files

 
Ali Ekber
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to include jar files in a new Jar file I want to create. Here is the command I am trying:

jar cmf mainClass SOAPClient.jar com/company/client/ soap.jar activation.jar mail.jar

When I create this jar file and run it, I get this error:

java -jar SOAPClient.jar
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException

So, obviously mail.jar is not included in the file correctly (wrong classpath??). How can I include mail.jar activation.jar and soap.jar in this new jar file?

Thx.
 
Paul Clapham
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You include those three jar files in the outer file exactly the way you did it. That part works fine. But then there is no way to declare the classpath so that it includes those three jar files, so it is pointless to do so.
 
Norm Radder
Rancher
Posts: 1222
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>How can I include mail.jar activation.jar and soap.jar in this new jar file?

You can't. There is no provision for the java command to look for jar files inside of another jar file. All the jar files MUST be as separate files in some folder.
See the Class-path: entry in the manifest as one possiblity.
Or use a full commandline: java -classpath <all the jars> <program>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic