批处理应用集锦[1]
make_jar.bat
@echo off
echo ===============================================================================
echo.
echo make_jar.bat 2017/02/17
echo.
echo jar-file generator by WangXiaodong~
echo.
echo ===============================================================================
echo.
SETLOCAL ENABLEDELAYEDEXPANSION
title jar-file generator by WangXiaodong~
cd /d %0\..
color 0a
set home=C:\Program Files (x86)\Java\jdk1.6.0_45\bin
set path=%path%;%home%
set tmp_dir=tmp
set lib_dir=lib
set src_dir=src
set jar_file=CommonTools.jar
set java_files=java_files.txt
set main_class=cn.dmdl.kernel.Controller
set manifest_file=MANIFEST.MF
set jar_file_set=third_party_jar_files.txt
set classpath_str=
set classpath_str2=
if exist %tmp_dir% rmdir /s /q %tmp_dir%
mkdir %tmp_dir%
if exist %jar_file% del /q %jar_file%
if exist %java_files% del /q %java_files%
if exist %manifest_file% del /q %manifest_file%
if exist %jar_file_set% del /q %jar_file_set%
dir /s /b %src_dir%\*.java > %java_files%
dir /b %lib_dir%\*.jar > %jar_file_set%
rem 生成清单文件、指定查找用户类文件和注释处理程序的位置
echo Class-Path: > %manifest_file%
for /f %%i in (%jar_file_set%) do (
echo ./%lib_dir%/%%i >> %manifest_file%
set classpath_str=./%lib_dir%/%%i;!classpath_str!
set classpath_str2=../%lib_dir%/%%i;!classpath_str2!
)
echo Main-Class: %main_class%>> %manifest_file%
rem 编译
javac @%java_files% -d %tmp_dir% -encoding UTF-8 -cp %classpath_str%
rem 测试
echo #################### 测试开始 ####################
cd %tmp_dir%
java -cp %classpath_str2% %main_class%
echo #################### 测试结束 ####################
rem 生成可执行jar-file
jar cvfm ../%jar_file% ../%manifest_file% -C ./ .
rem Not include third party jar-file.
rem jar ecvf %main_class% ../%jar_file% *
rem 清理
cd ..
rmdir /s /q %tmp_dir%
del /q %java_files% %manifest_file% %jar_file_set%
rem 测试2
echo #################### 测试开始 ####################
java -jar %jar_file%
echo #################### 测试结束 ####################
SETLOCAL DISABLEDELAYEDEXPANSION
pause
tiy.bat
@echo off
title TIY
cd /d %0\..
color 0a
set home=C:\Program Files (x86)\Java\jdk1.6.0_45\bin
set path=%path%;%home%
set jar_name=CommonTools.jar
cmd /k java -jar %jar_name%