File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes About JAR files... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About JAR files..." Watch "About JAR files..." New topic

About JAR files...

Chris Stewart
Ranch Hand

Joined: Sep 14, 2002
Posts: 184
I've packaged up a jar file with my classes and libs neatly placed in their directory structure. I've created a cmd file that will be used to call the main method of the application to start the application. I'm having trouble adding the libs within the jar to the classpath so my application can find and use them. Here is the code from my cmd file.

I know the SystemStart path is correct and that it takes an argument. When I run this script it gives me this.

Which tells me it isn't finding the lib files (the JavaMail jar files). Does anyone know the syntax for my classpath to add the jar files from inside my application jar file? Thanks for your time.
Pete Lyons
Ranch Hand

Joined: Aug 18, 2002
Posts: 109
It's easier if you make your jar file "executable" by adding this line to the META-INF/MANIFEST.MF file inside the jar:
Main-Class: com.home.rptsendmail.v2.SystemStart
and then run it with:
java -jar RptSendMail-2.0.0.jar
see The Jar File Tutorial
If you want to ship the javaMail stuff alongside your jar, use the manifest's Class-Path: entry like this (this may not be permissible by Sun though, so check the license carefully)
Download extensions are specified in the Class-Path header field in the manifest file of an applet, application, or another extension. A Class-Path header might look like this, for example:
Class-Path: servlet.jar infobus.jar acme/beans.jar
With this header, the classes in the files servlet.jar, infobus.jar, and acme/beans.jar will serve as extensions for purposes of the applet or application. The URLs in the Class-Path header are given relative to the URL of the JAR file of the applet or application.

Otherwise, just unjar all the classes you need and bundle them directly in your .jar (no nested jar files).
I agree. Here's the link:
subject: About JAR files...
It's not a secret anymore!