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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "setting classpath for multiple jar files" Watch "setting classpath for multiple jar files" New topic
Author

setting classpath for multiple jar files

satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
I want to identify all the dependent jars that I need for my code to run
( hence this exercise )

Using JDK 1.5


Trying to compile and run some code from the dos prompt ( purposefully not using Eclipse )

Now while I am able to compile the code I am getting errors while trying to run the same

Incrementally looking at the error - I am adding the necessary jar file in a specific directory .

I then execute the code similar to ::



My Problem is for every jar to be added in classpath manually is a pain

Is it possible to specify a wildcard like *.jar that will include all jars in specified dir

I tried the following ( didnt work )



Is there any other alternative that can be used ?

Thanks ,
~satish
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
I haven't seen any wildcards in the tool doc, but every release something changes so you need to keep reading the doc to see if/when it is allowed.

Are the number/names of jar files changing every time? Or are they constant?
Some solutions if the jar files remain constant:
Create a batch file with all the jar files specified in it.
Use Windows Explorer|Tools|File Types to set a commandline for jar files that you can select from the Rightclick context menu.
satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
Thanks Norm for the response

I tried doing some googling and looks like atleast till Java 1.6 cannot specify a directory that contains jars

Regarding the explorer >> tools >> Folder options >> File types

I am not sure I followed you .

Could you please elaborate how to go about it ?

Thanks ,
~satish
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
Originally posted by satish bodas:
I tried doing some googling and looks like atleast till Java 1.6 cannot specify a directory that contains jars


I guess you need to reconfigure Google to search the Sun Java website then

I haven't actually tried it myself, but according to this
java -classpath .;D:\zzz\* com.embeddable.Client
should work.

[Edit] - note however that you can't do this in a jar manifest classpath, so if you ever decide to package your application as a jar, you will need to know precisely which jar files are used.
[ July 29, 2008: Message edited by: Joanne Neal ]

Joanne
satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
Thanks Joanne for the link and it does mention the wildcard piece to include jars .

However I did try it out and it didnt work for me

Here is the link where they mention about version 1.6
In Java 1.6+, use a wildcard to include all jars in a directory into the set classpath or the command line -classpath


Thanks ,
~satish
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
I've had a little play and I got it to work. You need to put the classpath variable in quotes
java -classpath ".;D:\zzz\*" com.embeddable.Client
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting classpath for multiple jar files
 
Similar Threads
javac question
how to tell ant that some packages are needed?
running jar file error:
what jars are needed for jpa using hibernate
NoClassDefFoundError: org/springframework/context/ApplicationContext