<a href="http://yulimin.javaeye.com/blog/60385">将某一目录下所有的jar文件都加入到classpath当中的简便写法</a>
引用: http://www.javaeye.com/topic/244?page=2 中将某一目录下所有的jar文件都加入到classpath的写法,比较长:)
quake wang 写道
代码
for %%i in ("%hibern8ide%/*.jar") do call "setclasspath.bat" %%i
setclasspath.bat:
set _classpathcomponent=%1
:argcheck
if %2a==a goto gotallargs
shift
set _classpathcomponent=%_classpathcomponent% %1
goto argcheck
:gotallargs
set classpath=%_classpathcomponent%;%classpath%
简便写法如下:
setlocal enabledelayedexpansion
for %%i in ("xxx/lib/*.jar") do set classpath=!classpath!;%%~fsi
echo %classpath%
endlocal
第一句:启用变量延迟;
第二句:循环将.jar文件加入,并以短路径的形式加入;
比如:c:/program files/lib/xxx.jar
变为:c:/progra~1/lib/xxx.jar
第三句:显示设置后的classpath值;
第四句:还原系统环境设置
注意:第二句的!classpath! 与 %%~fsi 的写法,特别是!classpath!而不是%classpath%
如果是想以相对径的加入到classpath的话,就直接用
for %%i in ("./lib/*.jar") do set classpath=!classpath!;%%i
即可。
问题:我不知道以相对路径后,长文件名也可以自动以短文件名来表示的方法:(