Create a simple Java program
Run the following command to create the maven project wrapper-test.
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.freebird.app -DartifactId=wrapper-test
Then follow the prompts to perform the operation (Maven official documentation is a little outdated and out of touch with the latest situation ):
Choose a number or apply filter (Format: [groupid:] artifactid, case sensitive contains): 171:
Choose org. Apache. Maven. archetypes: Maven-Archetype-Quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6:
[Info] using property: groupid = com. freebird. app
[Info] using property: artifactid = wrapper-test
Define value for property 'version': 1.0-snapshot ::
[Info] using property: package = com. freebird. app
Confirm properties Configuration:
Groupid: COM. freebird. app
Artifactid: wrapper-test
Version: 1.0-Snapshot
Package: COM. freebird. app
Y: Y
Now, the project has been created. The Code is also simple:
package com.freebird.app;/** * Hello world! * */public class App { public static void main( String[] args ) { System.out.println( "Hello World!" ); }}
Execute MVN clean package into a jar file: wrapper-test-1.0-SNAPSHOT.jar
Download
Sudo-S
CD/usr
Wget http://wrapper.tanukisoftware.com/download/3.5.14/wrapper-linux-x86-64-3.5.14.tar.gz
Tar zxvf wrapper-linux-x86-64-3.5.14.tar.gz
Install
In ~ /. Add the following two sentences to the end of the bashrc file:
Export wrapper_home =/usr/wrapper-linux-x86-64-3.5.14
Export Path = $ wrapper_home/bin: $ path
Then execute:
Source ~ /. Bashrc
Configuration
Http://wrapper.tanukisoftware.com/doc/english/launch-nix.html
Http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/usage_jsw.html
Bin directory
Create the bin directory under the wrapper-test directory and copy some script files to the directory:
CD./bin
CP $ {wrapper_home}/bin/wrapper ./
CP $ {wrapper_home}/src/bin/sh. Script. in./MyApp
Edit the MyApp script file and modify the name:
# Application
App_name = "@ app. Name @"
App_long_name = "@ app. Long. Name @"
="
# Application
App_name = "MyApp"
App_long_name = "my application"
Note: The default configuration in the MyApp script requires a conf directory in the brother Directory, which requires a wrapper. conf file.
Wrapper_conf = "../CONF/wrapper. conf"
Conf directory
Create the conf directory under the wrapper-test directory and copy the configuration file to the directory:
CD./Conf
CP $ {wrapper_home}/src/CONF/wrapper. conf. in./wrapper. conf
Note that integration method 1 (wrappersimpleapp) is used by default)
Look here to know: http://wrapper.tanukisoftware.com/doc/english/integrate.html
Wrapper. java. mainclass = org. tanukisoftware. wrapper. wrappersimpleapp
However, the service I need is able to accept external stop and start commands, so I decided to use the second method. Therefore, I changed it:
Wrapper. java. mainclass = org. tanukisoftware. wrapper. wrapperstartstopapp
Then
Replace @ app. Name @ with MyApp
Replace @ app. Long. Name @ with my application
Replace @ app. Description @ with my first wrapper Application
Set the startup class to app.
# Application parameters. Add parameters as needed starting from 1
Wrapper. App. parameter.1 = com. freebird. App. app
Wrapper. App. parameter.2 = 1
Wrapper. App. parameter.3 = start
Wrapper. App. parameter.4 = com. freebird. App. app
Wrapper. App. parameter.5 = true
Wrapper. App. parameter.6 = 1
Wrapper. App. parameter.7 = stop
Reference for setting these parameters: http://wrapper.tanukisoftware.com/doc/english/integrate-start-stop-win.html#parameter
Basically, they are divided into two groups. I have already used empty rows to separate them. One group is used to set the startup class and startup parameters, and the other is used to set the closing class and closing parameters.
Logs directory
Create another sibling directory logs.
Lib directory
Create the lib directory, and copy the library files of the wrapper service.
CD lib
CP $ {wrapper_home}/lib/libwrapper. So ./
CP $ {wrapper_home}/lib/wrapper. Jar ./
Also put the wrapper-test-1.0-SNAPSHOT.jar file under the lib directory. Modify the wrapper. conf file:
# Java classpath (include wrapper. Jar) add class path elements
# Needed starting from 1
Wrapper. java. classpath.1 = ../lib/wrapper. Jar
Wrapper. java. classpath.2 = ../lib/wrapper-test-1.0-SNAPSHOT.jar
Console running
Return to the bin directory and execute the command:./MyApp Console
Two lines of Hello, world. are printed successfully.
For the first time Hello, world accepts the start parameter and starts the program. The second time is to accept the stop parameter and close the program. The reason for triggering the second main function call is that the main function is automatically stopped after the first main function is run and then monitored by wrappermanager. Therefore, the second call is initiated.
If you modify main, only one Hello, world appears.
package com.freebird.app;/** * Hello world! * */public class App { public static void main( String[] args ) { System.out.println(args.length); System.out.println(args[0]); System.out.println( "Hello World!" ); while(true){ try{ Thread.sleep(1000); }catch(Throwable ex){ } } }}