Java Service Wrapper installing the jar package as a Windows service

Source: Internet
Author: User

Just in touch with Java, the first time to use Java to develop Windows services, is also just recently saw the SSM framework

is also confused, but as long as the intentions to understand, in fact, is very simple, the following are detailed steps, bag learning package will

To run the jar package on Windows, you need to run the jar package in the working directory using the command line, so a command-line window appears

And this command-line window may be accidentally shut down, and the server after the start of the need to manually click to open

For some service programs, we need to deploy it as a Windows service that starts automatically when the system starts

Later, two ways were studied:

1. Installing the jar package with JavaService.exe

A lot of data, eventually this way is also feasible, you can successfully install the jar package into Windowservice

However, the JavaService.exe flaw is inconvenient to display the configuration parameters, and installation using DOS command

Javaservice provides 8 parameters to choose from, and here you will need to provide some other parameters related to the service when installing NT services using the-install parameter, with the following command format:
Javaservice-install service_name jvm_library [jvm_options]
-start Start_class [-method Start_method] [-params (start_parameters)]
[-stop Start_class [-method Stop_method] [-params (stop_parameters)]]
[-out Out_log_file] [-err Err_log_file]
[-current Current_dir]
[-path Extra_path]
[-depends Other_service]
[-auto |-manual]
[-shutdown seconds]
[-user user_name-password Password]
[-append |-overwrite]
[-startup seconds]
[-description Service_desc]

The following command installs the NT service in my own project:

Javaservice.exe-install testservice "%java_home%"/jre/bin/server/jvm.dll-xmx128m-djava.class.path= "%JAVA_HOME% "/lib/tools.jar;" %cd% "/lib/jtds-1.2.5.jar;" %cd% "-start com.azure.testservice-method startservice-stop com.azure.testservice-method stopservice-out"%CD% "/L Og/log.log-err "%cd%"/log/error.log-current "%cd%"-auto

After the service has been successfully installed, it can be uninstalled, started, and stopped with the following command.

Javaservice.exe-uninstall Testservice

net start Testservice

net stop Testservice

So later installation upgrade maintenance is also very troublesome, DOS command is also prone to error, not recommended , so find the following second way

2. Install the jar package using the Java Service Wrapper

The Java Service wrapper uses a visual configuration file to configure the parameters to be saved with ease and without increasing memory pressure

Refer to the following article before using:

http://www.blackzs.com/archives/679 (can refer to this article configuration artifacts, 3rd can be ignored since the Java Service Wrapper has a specific folder management)

http://286.iteye.com/blog/1921414 (This article explains in detail the meaning of the Java Service Wrapper configuration file)

After reference, ready to download the file, Java Service wrapper:http://wrapper.tanukisoftware.com/doc/english/download.jsp

Because my server is 64-bit, in the download time found that there is no free version of the 64-bit, but also worry about the other 2 versions to charge, it did not download the other 2 versions, looking for cracked version of the web, and finally downloaded on this site:

https://www.krenger.ch/blog/java-service-wrapper-3-5-14-for-windows-x64/

The version I downloaded is 3.5.14.

Then start the configuration:

1. Create a new folder on my server named JAR_JSW.

2. Unzip the downloaded zip package.

3. Create a new bin, Conf, Lib, logs folder under the new folder JAR_JSW, and copy the jar package that needs to be started to the JAR_JSW directory, my Jar package is: Processapp.jar

4. Copy the files from the Src\bin folder to the new Jar_jsw/bin folder. and remove all files in the suffix. Also put the Wrapper.exe under the bin in the Unpacked folder under the new bin

5. Copy the files in the Src\conf folder to the new Conf folder. Remove the in suffix, in fact there is only one file, namely wrapper.conf.

6. Put the Wrapper.jar and Wrapper.dll in the Unpacked folder into the new Lib. Also place the third-party jar package required to start the jar package.

7. Start configuring the wrapper.conf file. See other articles for configuration options.

8. After the configuration, click App.bat under the Bin folder to test, if you can have normal results in the console, it indicates that the configuration is correct. Then click Installapp-nt.bat to install the service, or click Uninstallapp-nt.bat Uninstall service. After the service is successfully installed, you can see it in Window service management.

Note: My jar package uses System.getproperty ("User.dir") to get the working directory, according to the default settings, I started the program to error, always reported missing files. So I am on the Internet to see if the JSW has modified the working directory parameters, and finally the reference:

Https://wrapper.tanukisoftware.com/doc/english/properties.html

Wrapper.working.dir This setting is found, so refer to its settings: https://wrapper.tanukisoftware.com/doc/english/prop-working-dir.html

When the working directory is modified, the corresponding parameters such as Classpath will need to be changed, as shown in the parameters. I modified everything after OK.

At this point, I wrapped the jar package into a Windows service complete.

Written in the back, I found that ACTIVEMQ is also a service installed using this method.

Exception handling

1, if the newspaper Org.tanukisoftware.wrapper.test.Main does not exist.

Wrapper.java.mainclass=org.tanukisoftware.wrapper.test.main
Modified into
Wrapper.java.mainclass=org.tanukisoftware.wrapper.wrappersimpleapp

In summary, if the related class does not exist, you should carefully review the configuration path, and whether Lib is congruent.

2. All errors are recorded under Log/wrapper.log.

3. The JVM did not exit on request, terminated, if you report this error stating that you are not configured as I wrote above, But the main program is configured in the Wrapper.java.mainclass, in fact, this configuration can also, but I do not write the same way, if you have to be written in Manclass, the specific solution can be consulted: http://bbs.csdn.net/ topics/90143848 View 10 floor answer.

4, there were 5 failed launches in a row, each lasting less than. Giving up. This error is caused by the configuration of the main method, note the path to Wrapper.app.parameter.1, and whether to remove the # before it.

Original: http://www.bubuko.com/infodetail-2169827.html (this article adds a few additions)

Java Service Wrapper installing the jar package as a Windows service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.