将 jar 文件添加到类路径
我正在制作一个构建脚本作为批处理文件(不要问我为什么或建议替代方案。你不会提供帮助)。我有一个名为 CLASSPATH 的变量,与 java 编译器一起使用。 CLASSPATH 包含许多目录和 jar 文件的路径。除此之外,我想添加 .[some-long-path]\lib\ 目录中的每个 jar 文件
它看起来像这样:
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%
这几乎可以工作。只有两个问题:
- 条目之间出现空格,这会破坏类路径。
- 它在 1024 个字符后突然结束。
有人可以帮我解决这个问题吗?
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 ALMOST 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 java6,则只需编写
dir/*
即可包含目录中的所有 jarhttp://download.oracle.com/javase/6/docs/technotes/tools/windows/javac.html
If you use java6, it's enough to write
dir/*
to include all jars in the dirhttp://download.oracle.com/javase/6/docs/technotes/tools/windows/javac.html
如果您正在运行
javac
,请尝试使用-classpath
命令行参数而不是环境变量,因为这些变量在不同操作系统上有大小限制。纯粹作为旁注,如果您从 JAR 运行程序(例如
java -jar app.jar
),您可以 添加元数据 执行完成相同操作的 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.