This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes put directory in classpath 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 » Beginning Java
Bookmark "put directory in classpath" Watch "put directory in classpath" New topic
Author

put directory in classpath

Susilo Saja
Ranch Hand

Joined: May 27, 2003
Posts: 91
I have a directory that contains a lot of jar file. Is it possible to put the directory in the classpath, instead of putting the jar file one by one?
Susilo
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi
no. there is no way to just put the directory in the classpath.
u can probably write a loop in the script (.bat on windows and shell script on unix/linux) to do that for u...
i usually write following loop to include every jar file in the classpath
for i in `ls $HOME/jars/*.jar`
do
CLASSPATH=$CLASSPATH:$i
done
export CLASSPATH
javac *.java
this is assuming unix/linux and bash shell on it. somebody can provide the script on windows as well...
same way u can include .zip files if there are...
regards
maulin
Malcolm Featonby
Greenhorn

Joined: Jun 18, 2003
Posts: 14
Hi,
It can be done but typically "- insert anti - Microsoft comment here -".
This will work on Windows 2000 machines. I have not tested it on anything else but I would imagine it should work on XP too.
First you need to make sure that Command Extensions and Delayed Expansion are enabled in your command shell. To do this make sure that the
following entries in your system registry (use REGEDT32 to check) are present and enabled (set to value 0x1).
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\DelayedExpansion
and
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensions
(You can also use a switch when running CMD.EXE to do this "CMD /EN /VN").
Once this is done the following script will do the same as the linux/unix script.
FOR %%I IN (*.jar) DO (
SET CLASSPATH=!CLASSPATH!%%~fI;
)
Hope this helps.
[ edited to disable the smilies -ds ]
[ June 21, 2003: Message edited by: Dirk Schreckmann ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Thanks for answering Susilo's question, Malcolm.
As part of my moderator duties, I have to request you to change your name according to JavaRanch's Naming Policy. In your case you have to add a lastname.
Thanks
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Susilo Saja
Ranch Hand

Joined: May 27, 2003
Posts: 91
Thanks guys, that really helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: put directory in classpath