YASJW批处理脚本中

时间:2017-07-10 11:58:17

标签: java windows batch-file service yajsw

我们公司希望将我们的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"

wrapper.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

1 个答案:

答案 0 :(得分:0)

我发现了问题,问题是,time_t ts = 1509238797L;//29.10.2017-02:59:57 3 seconds before dst struct tm* pre = localtime(&ts); time_t after = ts + 5L;//wait 5 seconds -> 29.10.2017-02:00:02 struct tm* post = localtime(&after); 我已经两次使用uninstallScript.bat,第一次调用改变了工作目录,因为我正在使用相对路径调用秒在解决路径时遇到了问题。

要解决此问题,我在当前目录中插入了call作为参数,并在第一个pushd a call之后插入了参数。

该文件现在看起来像这样:

popd