问题场景
写好了一个jar包,使用了Java8的新特性,需要发布给客户,考虑到客户并不一定会使用Java8,所以就把JRE8一起发布了,分为Windows和Linux两个版本,各自写了一个脚本来运行。
脚本
Windows:
client.bat
@echo off
rem The running environment of test.jar is jdk1.8 at least.
if "%OS%" == "Windows_NT" setlocal
rem ---------------------------------------------------------------------------
rem Start script for the xxx client
rem ---------------------------------------------------------------------------
set "CURRENT_DIR=%cd%"
set "JRE_HOME=%CURRENT_DIR%"
if exist "%JRE_HOME%\jre\bin\java.exe" goto okHome
cd ..
set "JRE_HOME=%cd%"
cd "%CURRENT_DIR%"
:okHome
set "EXECUTABLE=%JRE_HOME%\jre\bin\java.exe"
rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
:okExec
rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs
cd jre\bin
java -jar %JRE_HOME%\test.jar %CMD_LINE_ARGS%
:end
Linux:
client.sh
#!/usr/bin/env bash
# This is a shell for running test.
var="test"
dir=`pwd`
if [ ${var} = ${dir##*/} ];
then
./jre/bin/java -jar ${dir}/test.jar "$@"
else
echo "U should enter in directory ${var}, and type ./start.sh parameterlist"
fi
注意
jre/bin目录需要替换成自己本地jre目录文件夹名称
test.jar需要修改成自己工程的jar包名称
参考https://blog.csdn.net/sand_clock/article/details/72520452