Satellite is a set of utilities and Java support classes for running Java applications as server processes. Commonly known as 'daemon' processes in Unix terminology, on Windows they are called 'services'.
Compilation process is performed under Linux. Cross-compilation fanboy :-)
- Gradle 4.4.x
- Java Development Kit >= 7
- Clang 5.x
- mingw-w64-x86-64-dev (gcc 5.x)
- libc6-dev-i386
Writing an independent OS background process become pretty simple. The first step is to implement a java interface who manage background process behaviors. The second step require Phobos
or Deimos
depending if you are under Windows or Linux. The Daemon behavior has been designed as the same manner as Windows service. Under Windows, only certain service state transitions are valid. The following diagram shows the valid transitions (credits to Microsoft) :
In your project, add the Satellite API dependency (Maven POM):
<dependency>
<groupId>io.zatarox.satellite</groupId>
<artifactId>satellite-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
This is the facade of your service. Attention : calls on these methods are synchronous.
import io.zatarox.satellite.*;
public final class FooBackgroundProcess implements BackgroundProcess {
@Override
public void initialize(BackgroundContext dc) throws BackgroundException, Exception {
System.err.println("Initialized");
}
@Override
public void resume() throws Exception {
System.err.println("Started...");
}
@Override
public void pause() throws Exception {
System.err.println("Stopped !");
}
@Override
public void shutdown() {
System.err.println("Destroyed");
}
}
Finally, add a manifest entry in your main jar (and dependency jars OFC).
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<index>true</index>
<manifestEntries>
<Background-Process-Class>io.zatarox.satellite.FooBackgroundProcess</Background-Process-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
To a look to the sample project submodule to see how to get binary frontends from Gradle
This project is based on Apache Commons Daemon.