当社では、Java ServerアプリケーションをWindowsサービスとして簡単にインストールするため、YAJSWを使用してアプリケーションをラップしています。それを少し便利にするために、私は、サービスをインストール/アンインストール/開始/停止するためのクリックが必要な小さなバッチスクリプトを作成しました。YASJWバッチスクリプトのパスの動作が一貫していません
インストール、起動、停止はうまくいきますが、アンインストールを使用すると、ファイルが見つからないというエラーが表示されます。それらはすべて同じラッパー設定を使用し、すべてのバッチファイルは同じ場所にあるので、どのようにファイルを見つけることができないが、他のファイルは見つけることができないのだろうか?ここで
は私のフォルダ構造です:
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
者は、元のファイルの2、作業ものの一つと失敗thatsの一つです:
ここは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
で設定されています。
-i
の代わりに-r
を渡すことを除いて、同じです。
とにかく、それらは私のプロキシファイルです:正常に動作している
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
を私は本当にありませんここで何が間違っているかの手がかり、誰かが助けることを願っています
EDIT:
の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:私は、問題だった、それはuninstallScript.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
? 'setenv。バット 'は' setlocal'を含んでいません?パスを含む変数を引用していない理由はありますか?ファイルパスにスペースまたはアンパサンドが含まれていると、スクリプトが壊れます。 – rojo
私は最初はそうだと思っていましたが、明らかにプロパティファイルを読むラッパーは引用符が好きではありません。とにかく、それは私が不思議に思ったのはファイルの1つでは動作しません。 setenv.batを質問に追加して待ちます。 ラッパーは実際にはjarです。つまり、引用符を必要としないJavaプロパティapiを使用している可能性が最も高いです。 – ScriptKiddy
ただの一般的な見解ですが、あなたは 'set" varname = value "'の規約を使っているならば、明示的に引用符を付けるかどうかを問わず、スクリプトを破る可能性があると見なしてしまうという利点があります。こうすると値に引用符は含まれませんが、コンテンツはトークン化からまだ分離されています。文字列の値を 'set 'するたびに' 'variable = value''の組を引用する習慣を覚えてください。取得時に、必要に応じて ''%varname% ''を引用します。これによりコードが曖昧になり、読みやすくなります。 – rojo