File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Another classpath question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Another classpath question" Watch "Another classpath question" New topic
Author

Another classpath question

Warren Bell
Ranch Hand

Joined: Dec 20, 2000
Posts: 56
I have a stand alone app, public static void main(String[] args), that uses several other libraries (jars). I am able to get it to work, but listing all of the jar files in the classpath is a pain. How do I put everything including the extra jars in one jar and execute it and get my app to see all of the other jars it needs?

Most all of my experience is with j2ee. I have not done a stand alone app of this scope before.

Thanks,

Warren
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3219
You can't have a jar inside another jar. If you use JRE 6 + you can just specify the folder name in the classpath. You can have a folder called lib and then refer to it in your script.


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
Warren Bell
Ranch Hand

Joined: Dec 20, 2000
Posts: 56
So, I have to list every jar in my classpath? There is no other way of doing this? My command line to execute this is very long. How does an executable jar work? The app in an executable jar may still need to access other outside jars. I just want to easily make changes to my app like adding another library and not have to worry about classpaths all the time. It would be nice to just copy a new jar of my app and execute it like a war file works in a servlet container.

Warren
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Look for Understanding class path wildcards


SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38513
    
  23
Sounds too difficult a question for beginners'. Moving.
Yoav Weiss
Greenhorn

Joined: Nov 20, 2008
Posts: 11
Hi

having trouble with external jars & classpath too , i stumbled upon a nice plugin for eclipse called Fat-Jar.

not sure if this is what you are looking for , but take a look


http://fjep.sourceforge.net/
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2251
    
  47
Warren Bell wrote:So, I have to list every jar in my classpath? There is no other way of doing this? My command line to execute this is very long. How does an executable jar work?

The manifest file has Class-Path attribute where you list all the jars you want to be able to reference. See the Sun Tutorial.
 
jQuery in Action, 2nd edition
 
subject: Another classpath question