1.

Solve : SET CLASSPATH?

Answer»

I am trying to set a CLASSPATH variable to compile an application, the script should look for all .jar files in a directory and add the results on a local variable to give that variable to a JAVAC and compile the java classes...

I have the following script in a bat file but is not working

FOR /R D:\PATH\libs %%i IN (*.jar) DO SET CLASSPATH=%CLASSPATH%;%%~nxi;

When a put echo %CLASSPATH% I only SEE the last package found

D:\PATH>echo %CLASSPATH%
;mylib99.jar;

Could anyone tell me what am I doing wrong...

MANY THANKS IN ADVANCEIt is not CLEAR what you want to do.
How many jar files are there?
Why do you need to compile all at once?
If you were to do it manual, how long does it take?
What is the command line to do just one jar file?
And what did you want CLASSPATH to be?
There are many jar files, also I will need to use this script to set another jar files in other directories, if I had to do it manually it would be to MUCH. I want to have a local variable like the following:

SET DIR = /PATH/TO/LIBRARIES/
SET CLASSPATH=%DIR%lib1.jar;%DIR%lib2.jar;%DIR%lib3.jar;....;%DIR%libn.jar

The command I want to set after setting this variable is:

javac -target 1.X -classpath %CLASSPATH% %SOURCES%would the problem be delayed expansions?

If it is do the following:

- at the beginning of the batch file (before using the variable CLASSPATH) set the local variable EnableDelayedExpasion.
- Then, when referring to the variable use !var! instead of %var%.

SEARCH for more information.

Hope this helped;

Two-Eyes %OK. But you did not say how many. We need to know. There is a practical limit. Two practical limits.
1.) you can only have so much in one variable.
2.) In a huge process there has to be some kind of error recover.

If you have a massive job that has not already been tested, you avoid putting it in a loop. Professional programmers have the habit of writing 40 lines of commands for a batch file rather that put it in a FOR loop. They use the FOR loop for things they know will work well. But students and amateurs don't. They enjoy the challenge of using a shortcut even when it makes the job harder, longer, and pointless.

My recommendation, based on experience and observation, is use the FOR loop to create a long list of compiler commands that will compile each file one at a time. later. Maybe something like this:

Quote

javac -target 1.X -classpath D:\old\java2.jar
javac -target 1.X -classpath D:\new\java2.jar
javac -target 1.X -classpath D:\old\donut.jar
javac -target 1.X -classpath C:\fire\water.jar
...
You could call it MyBigJob.bat and if it does not work right, edit it with Notepad using global replace command.
The objective is not to see how concise you can make the job,
but how you can do the job right.

Is this of any help?
But if somebody else has a good answer, that's fine with me.


Discussion

No Comment Found