通過JavaService 將java jar包註冊成Windows 服務

來源:互聯網
上載者:User

標籤:wing   .com   目錄結構   檔案中   star   func   完成後   jar包   serve   

一、 下載Javaservice ,把壓縮檔解壓,放到本地磁碟。

JavaService 64位 http://download.forge.ow2.org/javaservice/JavaService_2_0_10-amd64.zip
JavaService 32位 http://download.forge.ow2.org/javaservice/JavaService-2.0.10.zip
二、 準備jar包,查看jar 包Main函數所在的class

三、 將jar包、解壓後的Javaservice執行程式、jdk免安裝包放在同一個檔案夾下,並在該檔案下建立err.log 和 out.log 檔案。
四、 註冊完成後可能會遇到“The LoadLibrary function failed for the following reason 找不到指定的模組的解決”的問題,為避免該問題,在此先進行處理。
方法1:拷貝%JAVA_HOME%/bin/msvcr100.DLL 檔案到C:\Windows\System32,
如果是64位系統還要拷貝到C:\Windows\SysWOW64。
方法2:拷貝%JAVA_HOME%/bin/msvcr100.DLL 檔案到到java程式打包成的jar檔案同一個目錄下
採用第二種方法,將java-1.8.0_172\jre\bin\msvcr100.dll拷貝到java 程式jar包所在的目錄下,這個目錄結構如下:

此時start.bat 為空白檔案
app 目錄下存放的檔案

五、 編寫bat指令碼(start.bat)
@echo off

rem Get the current path
set C_PATH=%CD%

rem Get the installation path
set /p "I_PATH=Please enter the installation path:"

rem Check whether the installation path exists.
rem If the path already exists ,exit.
rem if no exists,creation installation path.
if exist %I_PATH% goto I_PATH_EXIT
if not exist %I_PATH% goto I_PATH_ONT_EXIT

:I_PATH_EXIT
echo %I_PATH% Already exist, please replace
set /p "I_PATH=Please enter the installation path:"
if exist %I_PATH% goto I_PATH_EXIT
if not exist %I_PATH% goto I_PATH_ONT_EXIT

:I_PATH_ONT_EXIT
mkdir %I_PATH%\app

rem echo Copy the file to the installation directory
rem xcopy directory ,copy file
xcopy %C_PATH%\app %I_PATH%\app /s

@ timeout 3
rem Register as a service
%I_PATH%\app\JavaService.exe -install Hello-test "%I_PATH%\app\java-1.8.0_172\jre\bin\server\jvm.dll" -Xms256m -Xmx1024m -jar -Djava.class.path="%I_PATH%\app\java-1.8.0_172\lib\tools.jar;%I_PATH%\app\helloworld.jar" -start "org.springframework.boot.loader.JarLauncher" -out "%I_PATH%\app\out.log" -err "%I_PATH%\app\err.log" -current "%C_PATH%" -auto
@ timeout 5
net start Hello-test

rem Generate configuration file
echo 系統安裝路徑:%I_PATH%\app > %C_PATH%\confing.txt
echo 系統啟動命令:net start Hello-test >> %C_PATH%\confing.txt
echo 系統關閉命令:net stop Hello-test >> %C_PATH%\confing.txt
echo 可以通過服務啟動或關閉系統(已經配置開機自啟動 )>> %C_PATH%\confing.txt
echo 系統服務卸載命令:sc delete Hello-test >> %C_PATH%\confing.txt
pause
註:-start "org.springframework.boot.loader.JarLauncher" –start 後面的class 為第二步中查到的class名稱
六、 在Windows 10作業系統上進行測試(雙擊start.bat檔案)

看到上面的頁面,說明服務註冊成功,並已經啟動,按任意鍵退出即可。

七、 查看管理說明文檔

confing.txt 在成功啟動服務後自動產生

八、 查看安裝路徑檔案

其中out.log 檔案中記錄服務開機記錄
九、 參考文檔
41862831

通過JavaService 將java jar包註冊成Windows 服務

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.