The following shows how to generate start scripts to make an application run as a Linux daemon.
The setup is based on Java Service Wrapper (JSW) version 3.2.3, using the WrapperSimpleApp Integration.
In pom.xml:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<repositoryLayout>flat</repositoryLayout>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
<daemons>
<daemon>
<id>app1</id>
<mainClass>org.codehaus.mojo.SomeMainClass</mainClass>
<commandLineArguments>
<commandLineArgument>start</commandLineArgument>
</commandLineArguments>
<platforms>
<platform>jsw</platform>
</platforms>
</daemon>
</daemons>
</configuration>
<executions>
<execution>
<id>generate-jsw-scripts</id>
<phase>package</phase>
<goals>
<goal>generate-daemons</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>$ mvn package $ chmod +x target/jsw/app1/bin/app1 $ chmod +x target/jsw/app1/bin/wrapper-linux-x86-32 $ target/jsw/app1/bin/app1 start $ ps -ef | grep java (to check that it is running) $ target/jsw/app1/bin/app1 stop
E.g. add something like the following to your Main method:
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run() {
log.debug("Shutdown hook was invoked. Shutting down App1.");
App1JmxStopper appJmxStopper = new App1JmxStopper();
appJmxStopper.stop();
}
});