开发者

Add jar files to class path

I am making a build script as a batch file (don't ask me why or suggest alternatives. You won't be helping). I have a variable called CLASSPATH that I use with the java compiler. CLASSPATH contains paths to numerous directories and jar files. In addition to those, I'd like to add every jar file in the .[some-long-path]\lib\ directory

It looks something like this:

SET /p dummy=%CLASSPATH%>classpath.tmp~<nul 
SET WAR_LIB_PATH=war\WEB-INF\lib
DIR %WAR_LIB_PATH% /B | findstr /L ".jar" > jars.tmp~
REM Have to put it into an external file
FOR /f %%j in (jars.tmp~) do (
    SET /p dummy=;%WAR_LIB_PATH%\%%j>>classpath.tmp~<nul 
)
SET /P CLASSPATH=<classpath.tmp~
ECHO %CLASSPATH%

This ALMO开发者_如何转开发ST works. There are just two problems:

  • Somehow a space appears between entries, which ruins the classpath.
  • It abruptly ends after 1024 characters.

Can someone help me with this?


If you use java6, it's enough to write dir/* to include all jars in the dir

http://download.oracle.com/javase/6/docs/technotes/tools/windows/javac.html

For example, if directory foo contains a.jar and b.JAR, then the class path element foo/* is expanded to A.jar;b.JAR


If you are running javac, then try using the -classpath command-line argument instead of the environment variable, since those variables are size-limited on different operating systems.

And purely as a side note, if you are running a program from a JAR (ex java -jar app.jar), you can add metadata do the JAR file that accomplishes the same thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜