Skip to content

Instantly share code, notes, and snippets.

@borgle
Last active December 25, 2017 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borgle/f436368cd80290ad62753c1826eea799 to your computer and use it in GitHub Desktop.
Save borgle/f436368cd80290ad62753c1826eea799 to your computer and use it in GitHub Desktop.
从jdk安装文件中提取文件的批处理脚本,只需要一个额外的 7z.exe 就可以了。
@echo off
rem ---------------------------------------------------------------------------
rem name : extract script for the jdk installer
rem author : yoker.wu@gmail.com
rem date : 2017/12/21
rem ---------------------------------------------------------------------------
set CURDIR=%cd%
set BIN7Z=%CURDIR%\7z\7z.exe
set JAVA_HOME=%CURDIR%\jdk1.8.0_151
%BIN7Z% x -o%JAVA_HOME% jdk-8u151-windows-x64.exe
extrac32 %JAVA_HOME%\.rsrc\1033\JAVA_CAB10\111
rd /q /s "%JAVA_HOME%" >NUL 2>&1
%BIN7Z% x -o%JAVA_HOME% %CURDIR%\tools.zip
del "%CURDIR%\tools.zip" >NUL 2>&1
cd %JAVA_HOME%
for /r %%x in (*.pack) do .\bin\unpack200 -r "%%x" "%%~dx%%~px%%~nx.jar"
cd %CURDIR%
set RUNFILE=%CURDIR%\run.cmd
echo @echo off> %RUNFILE%
echo set JAVA_HOME=%JAVA_HOME%>> %RUNFILE%
echo set CLASSPATH=.;%%JAVA_HOME%%\lib;>> %RUNFILE%
echo set JAVA_BIN=%%JAVA_HOME%%\bin\java.exe>> %RUNFILE%
echo %%JAVA_BIN%% -version>> %RUNFILE%
echo %%JAVA_BIN%% -cp %%CLASSPATH%% -jar xxxxxxxxxxxxx.jar>> %RUNFILE%
set STOPFILE=%CURDIR%\stop.cmd
echo @echo off> %STOPFILE%
echo for /f "tokens=1,* delims== " %%%%i in ('"wmic process where (name="java.exe" and CommandLine LIKE "%%%%xxxxxxxxxxxxx.jar%%%%") get ProcessId /value | find "ProcessId""') do (>> %STOPFILE%
echo set PID=%%%%j>> %STOPFILE%
echo taskkill /f /t /pid %%PID%%>> %STOPFILE%
echo )>> %STOPFILE%
echo ok.
#!/bin/sh
# ---------------------------------------------------------------------------
# name : extract script for the jdk installer
# author : yoker.wu@gmail.com
# date : 2017/12/21
# ---------------------------------------------------------------------------
CURDIR=$(pwd)
tar -zxvf jdk-8u151-linux-x64.tar.gz
JAVA_HOME=$CURDIR/jdk1.8.0_151
RUN_FILE=$CURDIR/run.sh
cat >$RUN_FILE <<EOF
#!/bin/sh
export JAVA_HOME=$JAVA_HOME
export CLASSPATH=.:\$JAVA_HOME/lib
export JAVA_BIN=\$JAVA_HOME/bin/java
\$JAVA_BIN -version
\$JAVA_BIN -cp \$CLASSPATH -jar xxxxxxxxxxxxx.jar
EOF
chmod u+x $RUN_FILE
STOP_FILE=$CURDIR/stop.sh
cat >$STOP_FILE <<EOF
#!/bin/sh
pid=\$(ps -ef|grep xxxxxxxxxxxxx.jar | grep -v grep | awk '{print \$2}')
if [[ \$pid ]]; then
kill -9 \$pid 2>/dev/null
echo "OK"
else
echo "process not found."
fi
EOF
chmod u+x $STOP_FILE
printf 'ok'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment