• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting up classpath on a bat file

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if this goes here or beginner. I'm setting up a bat file
to run an application and I want to be able to access all jar files below a
directory. Can someone explain how to do this?

Thanks.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean that you want to dynamically set up the CLASSPATH based on the JARs in a particular directory? I'm certain I can do this in Linux with a bash script, but I'm not sure about the details in a Windows batch file. The process should be similar; it's the syntax that I don't know exactly. Anyways, here is what I would do in bash:

1) Capture the name of the files in the directory. In bash, I can capture the output of "ls" into a variable for later use. Windows batch files may provide something similar, except you use "dir" instead of "ls".

2) Use the variable above to fill in the -classpath flag for "java" and/or "javac"

It might not even be this complicated now that I think about it. You might be able to specify the classpath using glob matching:

javac -classpath c:\mydir\*.jar

HTH

-Layne

Disclaimer: No warranty explicit or implied is granted for using the above suggestions.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following only works on Windows NT/2000/XP/2003:

1- Create the following setcp.bat script:

2- Now suppose you want to set the CLASSPATH with all the .jar and .zip files under folder1 and folder2 folders,
do the following at the console:

> call setcp.bat "folder1" "folder2"
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic