Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Register a java jar package as a Windows service through JavaService

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

First, download Javaservice, extract the compressed file, and put it on the local disk.

Download address:

JavaService 64-bit http://download.forge.ow2.org/javaservice/JavaService_2_0_10-amd64.zip

JavaService 32-bit http://download.forge.ow2.org/javaservice/JavaService-2.0.10.zip

2. Prepare the jar package and view the class where the Main function of the jar package is located

Third, put the jar package, the extracted Javaservice executive program and the jdk installation-free package in the same folder, and create new err.log and out.log files under this file.

Fourth, after the completion of registration, you may encounter the problem that "The LoadLibrary function failed for the following reason can not find the solution of the specified module". In order to avoid this problem, deal with it here first.

Method 1: copy the% JAVA_HOME%/bin/msvcr100.dll file to C:\ Windows\ System32

If it is a 64-bit system, copy to C:\ Windows\ SysWOW64.

Method 2: copy the% JAVA_HOME%/bin/msvcr100.dll file to the same directory as the jar file packaged by the java program

Using the second method, copy java-1.8.0_172\ jre\ bin\ msvcr100.dll to the directory where the java program jar package is located, which is structured as follows:

Start.bat is an empty file at this time

Files stored in the app directory

Write bat script (start.bat)

@ echo off

Rem Get the current path

Set paid 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% iPATH% goto I_PATH_EXIT

If not exist% iPATH% goto I_PATH_ONT_EXIT

: I_PATH_EXIT

Echo% iTunPATH% Already exist, please replace

Set / p "I_PATH=Please enter the installation path:"

If exist% iPATH% goto I_PATH_EXIT

If not exist% iPATH% goto I_PATH_ONT_EXIT

: I_PATH_ONT_EXIT

Mkdir% Illumination path%\ app

Rem echo Copy the file to the installation directory

Rem xcopy directory, copy file

Xcopy% Cellular path%\ app% Illustrated path%\ app / s

@ timeout 3

Rem Register as a service

% Isuch path%\ app\ JavaService.exe-install Hello-test "% Illustrated path%\ app\ java-1.8.0_172\ jre\ bin\ server\ jvm.dll"-Xms256m-Xmx1024m-jar-Djava.class.path= "% Illustrated path%\ app\ java-1.8.0_172\ lib\ tools.jar % iTunes path%\ app\ helloworld.jar "- start" org.springframework.boot.loader.JarLauncher "- out"% Illustrated path%\ app\ out.log "- err"% Illustrated path%\ app\ err.log "- current"% compressed path% "- auto

@ timeout 5

Net start Hello-test

Rem Generate configuration file

Echo system installation path:% iTunes path%\ app >% accounts path%\ confing.txt

Echo system startup command: net start Hello-test > >% Cellular path%\ confing.txt

Echo system shutdown command: net stop Hello-test > >% accounts path%\ confing.txt

Echo can start or shut down the system through the service (boot is configured) > >% Cellular path%\ confing.txt

Echo system service uninstall command: sc delete Hello-test > >% Cellular path%\ confing.txt

Pause

Note:-start "org.springframework.boot.loader.JarLauncher"-the class after start is the class name found in step 2.

Test on the Windows 10 operating system (double-click the start.bat file)

See the above page, indicating that the service has been registered successfully and has been started, press any key to exit.

7. Check the management instructions

Confing.txt is automatically generated after successfully starting the service

Check the installation path file

The service startup log is recorded in the out.log file

IX. Reference documents

Https://blog.csdn.net/cxj1990year/article/details/41862831

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 273

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report