Java YASJW批处理脚本中的路径行为不一致

Java YASJW批处理脚本中的路径行为不一致,java,windows,batch-file,service,yajsw,Java,Windows,Batch File,Service,Yajsw,我们公司希望将Java服务器应用程序作为windows服务轻松安装,因此我们使用YAJSW来包装应用程序。为了方便起见,我创建了一些小批量脚本,只需单击即可安装/卸载/启动/停止服务 安装、启动和停止工作正常,但在使用卸载时,我收到一个错误,无法找到某些文件。它们都使用相同的包装器配置,并且所有批处理文件都位于同一个位置,所以为什么一个文件找不到,而其他文件找不到 以下是我的文件夹结构: lib\ |---YAJSW |----bat\ | |--- installServ

我们公司希望将Java服务器应用程序作为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
这是两个原始文件,一个正常工作,另一个失败:

这是卸载服务的
bat

pushd %~dp0
call setenv.bat
%wrapper_bat% -r %conf_file%
popd
pushd %~dp0
call setenv.bat
%wrapper_bat% -i %conf_file%
popd
这是installService.bat的
installService.bat

pushd %~dp0
call setenv.bat
%wrapper_bat% -r %conf_file%
popd
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"

我发现了问题,问题是,在
uninstallScript.bat
中,我使用了
call
两次,第一次调用更改了工作目录,因为我使用的是相对路径,第二次调用在解析路径时遇到了问题

为了修复它,我在第一次
调用
a
popd
的开始和之后插入了一个
pushd
,当前目录作为参数

该文件现在如下所示:

pushd %~dp0
call stopService.bat
popd
call lib\YAJSW\bat\uninstallService.bat 

如何定义
%wrapper\u bat%
setenv.bat
不包括
setlocal
是吗?有什么理由不引用任何包含路径的变量吗?如果一个文件路径包含一个空格或一个符号,你的脚本就会中断。起初我是这么认为的,但显然读取属性文件的包装器不喜欢引号。无论如何,它只在其中一个文件中不起作用,这让我感到奇怪。我将把setenv.bat添加到问题中,等等。包装器实际上是一个jar,这意味着它很可能使用不需要引号的Java properties api。这只是一个一般性的观察,但是如果使用约定
设置“varname=value”
,您将获得引用可能破坏脚本的缺点的好处,同时保留引用或不引用的显式功能。这样,值不包含引号,但内容仍然与标记化隔离。养成每次设置字符串值时引用
“variable=value”
对的习惯。检索时,根据需要使用引用的
“%varname%”
。这消除了代码的歧义,使其更易于阅读。您的路径名在
setenv.bat
中使用前斜杠的原因是什么?使用反斜杠会破坏Java语言吗?
rem
out
@echo off
in
setenv.bat
以及脚本中出现的任何地方。这是追踪到底哪里出了问题的最好方法。