bat:
运行Java程序,脚本中的主要操作是设置classpath.脚本的功能:(1)设置path:可以找到java命令(2)设置splash(启动画面)(3)设置classpath:主程序运行时找到引用的class(4)设置远程调试需要的相关参数
@echo off if "%OS%"=="Windows_NT" @setlocal if "%OS%"=="WINNT" @setlocal @title RRU Hotload Patch tool set workpath=%~dp0 set path=%path%;%workpath%\lib set JAVA_HOME=%workpath%\jdk-windows rem set JAVA_OPTS=%JAVA_OPTS% -splash:%workpath%\img\welcome.gif set JAVA_OPTS=%JAVA_OPTS% -classpath %workpath%\lib\*; rem set JAVA_OPTS=-classic -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=3999,server=y,suspend=n %JAVA_OPTS% %JAVA_HOME%\bin\java %JAVA_OPTS% PackageName.ClassName
Analyze:
[email protected] off
(1). 作为控制批处理命令在执行时是否显示命令行自身的开关
格式:ECHO [ON|OFF]
(2). 关闭DOS命令提示符
在DOS提示符状态下键入ECHO OFF,能够关闭DOS提示符的显示使屏幕只留下光标,直至键入ECHO ON,提示符才会重新出现.
http://network.51cto.com/art/201009/225457.htm
@的用法参见:http://www.cnblogs.com/softidea/p/4229829.html
2.%OS%是个系统变量
3.setlocal
setlocal /? 开始批处理文件中环境改动的本地化操作。在执行 SETLOCAL 之后 所做的环境改动只限于批处理文件。要还原原先的设置,必须执 行 ENDLOCAL。达到批处理文件结尾时,对于该批处理文件的每个 尚未执行的 SETLOCAL 命令,都会有一个隐含的 ENDLOCAL 被执行。
eg:
@echo off set test=test echo %test% setlocal echo after setlocal echo %test% set test=newContent echo %test% endlocal echo after endlocal echo %test%
Output:
test after setlocal test newContent after endlocal test
http://www.jb51.net/article/36043.htm
扩展:
setlocal enabledelayedexpansion
eg:
@echo off set a=4 set a=5&echo %a% echo ========================== setlocal enabledelayedexpansion set a=4 set a=5&echo !a! echo %a% pause
Output:
4 ========================== 5 5 请按任意键继续. . .
http://www.jb51.net/article/29323.htm
4、title
title /? 设置命令提示窗口的窗口标题。 TITLE [string] string 指定命令提示窗口的标题。
5、%~dp0
http://www.cnblogs.com/softidea/p/4229829.html
6、-splash
java -help Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) -splash:<imagepath> show splash screen with specified image
7、-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=3999,server=y,suspend=n
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,address=3999,suspend=n -XDebug 启用调试。 -Xnoagent 禁用默认sun.tools.debug调试器。 -Djava.compiler=NONE 禁止 JIT 编译器的加载。 -Xrunjdwp 加载JDWP的JPDA参考执行实例。 transport 用于在调试程序和 VM 使用的进程之间通讯。 dt_socket 套接字传输。 dt_shmem 共享内存传输,仅限于 Windows。 server=y/n VM 是否需要作为调试服务器执行。 address=3999 调试服务器的端口号,客户端用来连接服务器的端口号。 suspend=y/n 是否在调试客户端建立连接之后启动 VM 。
http://www.blogjava.net/yongbing/articles/221179.html
Extension part:
linux:
echo "Add the XXX‘s Lib path into the CLASSPATH..." CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar oldClsPath=$CLASSPATH LIPPATH=/opt/system/jakarta-tomcat-5.0.28/webapps/JavaService/WEB-INF/lib/*.jar #echo $LIPPATH cf=. for i in $LIPPATH do cf=$cf:"$i" #echo $cf done echo "The XXX‘s Lib path have been added into the CLASSPATH..." #echo $cf export CLASSPATH=$CLASSPATH:$cf echo $CLASSPATH #ps: if you want to run a java application, you must be copy this .bat file to the class directory. java -cp CLASSPATH PackageName.ClassName #ok
windows:
@echo off if "%OS%"=="Windows_NT" @setlocal if "%OS%"=="WINNT" @setlocal setlocal ENABLEDELAYEDEXPANSION ECHO. ECHO "Set CLASSPATH begin..." set CP=. for %%k in ("D:/Program Files/apache-tomcat-6.0.16/webapps/axis/WEB-INF"/lib/*.jar) do set CP=!CP!;%%k set CLASSPATH=%CLASSPATH%;%CP% ECHO "Set CLASSPATH is ok..." ECHO "Show the CLASSPATH: " ECHO. ECHO %CLASSPATH% ECHO. rem "you can add some code here." rem ps: if you want to run a java application, you must be copy this .bat file to the class directory. rem java -cp CLASSPATH PackageName.ClassName rem "" rem "" PAUSE
http://blog.csdn.net/faye0412/article/details/2986516
时间: 2024-10-12 15:45:32