Publishing Java services using JavaService.exe (AMD64) (JDK x64)

Source: Internet
Author: User
Tags goto

Java services are needed in recent projects, but Java services have been written, waiting to be deployed to Windows services, encountering difficulties------deploying JDK x64 compiled jars in the x64 server, encounters a variety of entanglements.

This article found a solution (a solution for deploying Java services in a x64 server, JDK x64 Java environment):

First of all, we have selected the tool is JavaService.exe, the latest version is:2.0.10

: http://forge.ow2.org/projects/javaservice/

After that, unzip the downloaded

Finally, compile the Java Service Program jar package that you want to deploy:

Then, organize the directory structure to deploy the Java service:

1, set up the Java service installation directory as: D:\JAVA_STUDY\WINDOWSSERVICE\JAVASERVICE_2_0_10-AMD64

2, copy the compiled Testtimer.jar package to the root directory of the service installation directory: D:\Java_Study\windowsservice\JavaService_2_0_10-amd64\TestTimer.jar;

and copy Testtimer Engineering dependent external package Log4j-1.2.17.jar to the root directory of the service installation directory: D:\Java_Study\windowsservice\JavaService_2_0_10-amd64\bin\ Log4j-1.2.17.jar;

3, copy the JavaService.exe files extracted from Javaservice_2_0_10-amd64.zip to D:\Java_Study\windowsservice\JavaService_2_0_10-amd64\ JavaService.exe;

4, organize Install.bat and Uninstall.bat.

Install.bat:

1@echo off2 rem Modify Console color3 Color 1d4REM *use Javaservice to install Testtimer as a script for Windows services5REM *6rem * Javaservice-windows NT Service Daemon forJava Applications7REM * Copyright (C) 2006Multiplan Consultants Ltd. LGPL Licensing applies8REM *information about the Javaservice software was available at the ObjectWeb9REM * Web site. Refer to Http://javaservice.objectweb.org forMore details. Ten REM begins localization of environment changes in batch files, and the environment reverts to the original content after using endlocal One SETLOCAL A REM SET environment variable, point to current path -SET base_path=%cd% - REM Set Java path:jre_home theSET jre_home=d:\java_study\java\jdk1.7. 0_79 -    - REM Determines if Jre_home is correct - if "%jre_home%"==""Goto No_java + ifNot exist"%jre_home%\bin\java.exe"Goto No_java -    + rem Setting JVM memory allocation ASet jvm_memory=-xms128m-xmx256m at rem Setting Jvmdll which mode to use -SET jvmdll=%jre_home%\jre\bin\server\jvm.dll - ifNot exist"%jvmdll%"Goto No_java -    - rem Setting Javaservice path -Set jsbindir=d:\java_study\windowsservice\javaservice_2_0_10-AMD64 inSet jsexe=%jsbindir%\javaservice.exe -    to REM Determines if jar is correct +SET acctjar=%base_path%\testtimer.jar - ifNot exist"%acctjar%"Goto No_peer the    *@Echo. Using following version of Javaservice executable: $@Echo. Panax Notoginseng "%jsexe%"-version -@Echo.  the    + rem parameters and files seem ok, go ahead with the service installation A@Echo.  the    + REM Processing input parameters for this batch, background service startup mode: Automatic -SET svcmode= $ if "%1"=="-manual"SET svcmode=-Manual $ if "%1"=="-auto"SET svcmode=-Auto -    - rem Settings java_opts theSet java_opts=%java_opts%-djava.class.path="%base_path%\bin\log4j-1.2.17.jar;%base_path%\testtimer.jar"   -Set java_opts=%java_opts%%jvm_memory%Wuyi    the rem Settings Startstop -SET start_stop=-Start Cn.test.timer.TestTimer Wu    -    About rem Setting log file path $Set Out_err=-out"%base_path%\service_out.log"-err"%base_path%\service_err.log"   -    - rem Settings Desp -Set Desp=-description"Testtimer Service"    A    + rem Settings execution command line theSet runcmd="%jsexe%"-Install Testtimerservice -Set runcmd=%runcmd%"%jvmdll%" $Set runcmd=%runcmd%%java_opts% theSet runcmd=%runcmd%%start_stop% theSet runcmd=%runcmd%%out_err% theSet runcmd=%runcmd%- Current theSet runcmd=%runcmd%"%base_path%" -Set runcmd=%runcmd%%svcmode% inSet runcmd=%runcmd%-Overwrite theSet runcmd=%runcmd%-startup 6 theSet runcmd=%runcmd%%desp% AboutEcho%runcmd% the  the rem Execution installation command the%runcmd% + REM Start-up service - net start Testtimerservice the   Bayi ifERRORLEVEL 1Goto Js_error theGotoEnd   the : No_java -@Echo. No Java runtime environment, installation scripts cannot run - Goto Error_exit the : No_peer the@echo. boot file Testtimer.jar not present, Setup script cannot run the Goto Error_exit the : No_jsexe -@echo. executable file JavaService.exe not present, Setup script cannot run the Goto Error_exit the : Js_error the@Echo. Testtimerservice An error occurred while installing as a service, check the relevant log file94 Goto Error_exit the : Error_exit the  the@Echo. 98@Echo. Installation failed and Testtimer cannot be installed as a Windows service About@Echo.  -@echo. command format:101@Echo. 102@echo. %~n0 [-auto/-manual] [-NP]103@Echo. 104@Echo. Where: the@echo. -auto (default) or-The manual parameter describes the startup mode of the service: automatic or manual106@echo. -NP Batch command does not pause after execution107@Echo. 108@Echo. For example:109@echo. %~n0-auto-NP the:End111  the endlocal113@Echo.  the if "%2"NEQ"-NP"@pause
View Code

Uninstall.bat

1@echo off2   3 rem Modify Console color4 Color 1d5   6REM *to uninstall the Testtimerservice service script using Javaservice7REM *8rem * Javaservice-windows NT Service Daemon forJava Applications9REM * Copyright (C) 2006Multiplan Consultants Ltd. LGPL Licensing appliesTenREM *information about the Javaservice software was available at the ObjectWeb OneREM * Web site. Refer to Http://javaservice.objectweb.org forMore details.  A    - REM begins localization of environment changes in batch files, and the environment reverts to the original content after using endlocal - SETLOCAL the    - REM Setting Environment variables -SET base_path=D:\Java_Study\windowsservice -    + REM Setting the path to Javaservice -Set jsbindir=%base_path%\javaservice_2_0_10-AMD64 +Set jsexe=%jsbindir%\javaservice.exe A    at rem Uninstall service before stopping service - net stop Testtimerservice -    - rem Settings execution command line -Set runcmd="%jsexe%"-Uninstall Testtimerservice -    in%runcmd% -    to@Echo.  +    - endlocal the@Echo.  * if "%2"NEQ"-NP"@pause
View Code

The Organized directory structure is:

Deploy the Java service and start the service using JavaService.exe:

Run install. Bat

During the run, if the line is positive, the CMD screen information is as follows:

installation directory structure changes:

To stop and uninstall a service:

Run Uninstall. Bat.

During the run, if the line is positive, the CMD screen information is as follows:

Reference article: "Javaservice" Deployment Java jar for Windows backend service http://blog.csdn.net/alibert/article/details/49944721 "

"Javaservice the jar as a Windows service http://blog.csdn.net/alibert/article/details/49944823"

Publishing Java services using JavaService.exe (AMD64) (JDK x64)

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.