Do you often write a shell script and batch file to run your jvm application, and how often do you copy from another project?
You can use the appassembler-maven-plugin to generate scripts to launch our program and create a daemon from it. The plugin does all the routine work on configuring java service wrapper , generating scripts and building the application for us.
But we will simplify our lives and use an automated solution for creating skeleton maven artifacts to build our demons. The com.github.igor-suhorukov plugin generator: daemon-archetype for maven, which is available in the central repository and on github . And under the hood is still appassembler-maven-plugin!
')
All that needs to be done to create the daemon skeleton is to execute the create command interactively and then configure what happened for the project:
Important note! The java service wrapper daemon stops with a SIGINT signal, so in order to properly release resources, you must register your Runtime.getRuntime (). AddShutdownHook (...).
Configuration of the daemon-archetype plugin.
The parameters groupId, artifactId, version do not deserve special attention, since they are required by any archetype plugin and this is what will be in the corresponding pom.xml tags.
With the entry-point-class parameter, you must specify the fully qualified class name, the public static void main (String []) method of which the daemon will call upon startup. In the case of a java application, you can specify a class with the main method both from the main-artifact * project dependency and from the current project's src / main / java directory.
The parameters main-artifact-artifactId, main-artifact-groupId, main-artifact-version indicate a dependency that contains an entry-point-class . The assembly also packs transitive dependencies for main-artifact *.
launcher-name defines the name of the daemon script in the bin directory.
Example: gitblit server git daemon.
For the test, create a daemon running the git server. Having executed the command in the console, or specifying the same parameters in the interactive mode:
After building in the target directory, there will be an archive with the daemon: gitblit-launcher-1.0-SNAPSHOT-daemon.tgz and two archives in tgz and zip format with the usual scripts to run the console application gitblit-launcher-1.0-SNAPSHOT-assembly.tgz, gitblit- launcher-1.0-SNAPSHOT-assembly.zip.
The Groovy script downloads gitblit.war from the project repository, unpacks it into the user's home directory and replaces the path to the repository repository in the gitblit configuration. After that, it starts the jetty server and gitblit inside it.
gitblit.groovy
import com.github.igorsuhorukov.smreed.dropship.MavenClassLoader @Grab(group='org.codehaus.plexus', module='plexus-archiver', version='2.10.2') import org.codehaus.plexus.archiver.zip.ZipUnArchiver @Grab(group='org.codehaus.plexus', module='plexus-container-default', version='1.6') import org.codehaus.plexus.logging.console.ConsoleLogger @Grab(group = 'org.eclipse.jetty', module = 'jetty-runner', version = '9.3.7.RC1' ) import org.eclipse.jetty.runner.Runner def gitblit = new File(MavenClassLoader.using('http://gitblit.imtqy.com/gitblit-maven').resolveArtifact('com.gitblit:gitblit:war:1.7.1').getFile()) File gitblitDirectory = new File(System.getProperty('user.home'), gitblit.getName().replace('.war','')) if(!gitblitDirectory.exists()){ gitblitDirectory.mkdir() ZipUnArchiver unArchiver = new ZipUnArchiver() unArchiver.setSourceFile(gitblit) unArchiver.enableLogging(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG,"Logger")) unArchiver.setDestDirectory(gitblitDirectory) unArchiver.extract() def dataPath = new File(System.getProperty('user.home'), '.gitblit_data') if(!dataPath.exists()){ dataPath.mkdir() } def webXml = new File(gitblitDirectory.getAbsoluteFile(), 'WEB-INF/web.xml') webXmlText = webXml.text webXml.withWriter { w -> w << webXmlText.replace('${contextFolder}/WEB-INF/data', dataPath.getAbsolutePath()) } } Runner.main([gitblitDirectory] as String[])
You can see a screencast with an example of the creation and operation of a demon.
You can create a daemon and scripts to build an application with just one command.