我们公司希望轻松地将我们的 Java Server 应用程序安装为 Windows 服务,因此我们使用 YAJSW 来包装应用程序。为了让它更方便一点,我创建了一些小批量脚本,只需单击即可安装/卸载/启动/停止服务。
安装、启动和停止工作正常,但是在使用卸载时,我收到一个错误,即找不到某些文件。他们都使用相同的包装器配置,并且所有批处理文件都位于同一个位置,那么怎么可能一个找不到文件而其他人却找不到呢?
这是我的文件夹结构:
lib\
|---YAJSW
|----bat\
| |--- installService.bat
| |--- uninstallService.bat
| |--- and so on
|----conf\
|--- wrapper.conf
MyApplication.jar
installService.bat //Basically a proxy batch doing some other stuff and then calling the original installService.bat
uninstallService.bat //Also a proxy
startService.bat //Proxy
stopService.bat //Proxy
这些是两个原始文件,一个工作文件和一个失败的文件:
这是uninstallService.bat
:
pushd %~dp0
call setenv.bat
%wrapper_bat% -r %conf_file%
popd
这是installService.bat
:
pushd %~dp0
call setenv.bat
%wrapper_bat% -i %conf_file%
popd
如果有人想知道%conf_file%
从哪里来,那setenv.bat
就像运行任务所需的其他东西一样。
它们是相同的,除了一个是通过-r
而不是-i
。
无论如何,这些是我的代理文件:
installService.bat
这工作正常:
::Make a clean copy of our default config
xcopy /y /Q lib\YAJSW\conf\wrapper.conf.default lib\YAJSW\conf\wrapper.conf
::Set current workingdirectory to current executing directory
SET workingdir=%cd%
::Replace all backslashes with 4 backslashes to keep YAJSW functioning
SET workingdirFixed=%workingdir:\=/%
::Set the working directory to the variable that we set up before
echo wrapper.working.dir=%workingdirFixed% >> lib\YAJSW\conf\wrapper.conf
::Call the install batch file which uses the config that we have created
call lib\YAJSW\bat\installService.bat
uninstallService.bat
这不起作用:
call stopService.bat
call lib\YAJSW\bat\uninstallService.bat
我真的不知道这里出了什么问题。
编辑
setenv.bat:
@echo off
rem quotes are required for correct handling of path with spaces
rem default java home
set wrapper_home=%~dp0/..
rem default java exe for running the wrapper
rem note this is not the java exe for running the application. the exe for running the application is defined in the wrapper configuration file
set java_exe="java"
set javaw_exe="javaw"
rem location of the wrapper jar file. necessary lib files will be loaded by this jar. they must be at <wrapper_home>/lib/...
set wrapper_jar="%wrapper_home%/wrapper.jar"
set wrapper_app_jar="%wrapper_home%/wrapperApp.jar"
rem setting java options for wrapper process. depending on the scripts used, the wrapper may require more memory.
set wrapper_java_options=-Xmx30m -Djna_tmpdir="%wrapper_home%/tmp" -Djava.net.preferIPv4Stack=true
rem wrapper bat file for running the wrapper
set wrapper_bat="%wrapper_home%/bat/wrapper.bat"
set wrapperw_bat="%wrapper_home%/bat/wrapperW.bat"
rem configuration file used by all bat files
set conf_file="%wrapper_home%/conf/wrapper.conf"
rem default configuration used in genConfig
set conf_default_file="%wrapper_home%/conf/wrapper.conf.default"
包装器.bat:
echo %java_exe% %wrapper_java_options% -jar %wrapper_jar% %1 %2 %3 %4 %5 %6 %7 %8 %9
%java_exe% %wrapper_java_options% -jar %wrapper_jar% %1 %2 %3 %4 %5 %6 %7 %8 %9