一个用批处理(BAT)回运行web工程的例子(jetty)
本代码是为了用BAT(批处理)来完整展示java的编译和执行过程。为方便理解,添加较多备注
下面是代码:保存为.bat格式即可双击运行。如果你想使用,只要更改红色字体部分与你实际代码的相对位置相符即可。
@echo *********************************************************************************
@echo **** enter into the folder of current file **********
@echo **** 1,make sure that this file is in root folder **********
@echo *********************************************************************************
set DIRNAME=.\
if "%OS%" == "Windows_NT" set DIRNAME=%~dp0%
%~d0
cd %DIRNAME%\..
@echo *********************************************************************************
@echo **** set the CLASSPATH **********
@echo **** 1,find the .jar in root folder **********
@echo **** eg: for /r %CD% %%i in (*.jar) do echo "%%i" **********
@echo **** if you want to add var ,you must use this **********
@echo "setlocal enabledelayedexpansion" and !var! as follows **********
@echo *********************************************************************************
setlocal enabledelayedexpansion
for /r %CD% %%i in (*.jar) do (
set CLASSPATH=!CLASSPATH!;%%i
)
@echo *********************************************************************************
@echo **** compile the .jar file--do not forget the classpath *********
@echo *********************************************************************************
javac -classpath %CLASSPATH% src/test/jetty/OneWebApp.java-d %CD%/build/classes
@echo *********************************************************************************
@echo **** run--do not forget the classpath else if you use it in compile *********
@echo *********************************************************************************
cd build/classes
@echo javaw test.jetty.OneWebApp
java test.jetty.OneWebApp
pause
- 1楼QQ635785620前天 17:41
- 自己顶一下