-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demo: Add junixsocket-demo-jpackagejlink
Demonstrates how to use jlink/jpackage with junixsocket. #153
- Loading branch information
1 parent
0d8ca6a
commit eca5410
Showing
5 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# junixsocket-demo-jpackagejlink | ||
|
||
Example code to demonstrate how to use junixsocket with jlink and jpackage. | ||
|
||
## Definitions | ||
|
||
### jlink | ||
|
||
jlink builds Java runtime images that are tailored towards a specific set of Java classes / modules. | ||
|
||
jlink was introduced in Java 9. | ||
|
||
### jpackage | ||
|
||
jpackage builds native installers for applications, utilizing optimized runtimes very much like jlink. | ||
|
||
jpackage was introduced in Java 14. | ||
|
||
## The demo code | ||
|
||
This demo simply runs a very simple selftest built into junixsocket-common. | ||
|
||
It depends on `junixsocket-core`, which is a POM-only dependency that in turn references | ||
`junixsocket-common` (the common junixsocket API) and `junixsocket-native-common` (the | ||
native library images for common operating systems). | ||
|
||
## Build instructions | ||
|
||
The main purpose of this Maven module is to demonstrate how to configure a project's `pom.xml` file | ||
such that jlink/jpackage-compatible artifacts can be created. | ||
|
||
By default, this demo does not create executable jlink/jpackage artifacts. | ||
You have to invoke the `mvn` command with a given profile setting to enable them: | ||
|
||
cd junixsocket-demo-jpackagejlink | ||
mvn clean verify -Djpackage -Djlink | ||
|
||
Omit either `-Djpackage` or `-Djlink` if desired. | ||
|
||
See the [junixsocket-demo-jpackagejlink POM file](pom.xml) for how this is done. | ||
|
||
## Results | ||
|
||
See `junixsocket-demo-jpackagejlink/target/jpackage` for the binary package result (the actual file | ||
depends on your target platform). | ||
|
||
See `junixsocket-demo-jpackagejlink/target/jlink/image` for the Java runtime optimized for the demo | ||
code. | ||
|
||
## References | ||
|
||
* [Tools Reference: jlink](https://docs.oracle.com/en/java/javase/11/tools/jlink.html) | ||
* [Tools Reference: jpackage](https://docs.oracle.com/en/java/javase/14/docs/specs/man/jpackage.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>junixsocket-demo-jpackagejlink</artifactId> | ||
<packaging>jar</packaging> | ||
<parent> | ||
<groupId>com.kohlschutter.junixsocket</groupId> | ||
<artifactId>junixsocket</artifactId> | ||
<version>2.9.1-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<name>junixsocket-demo-jpackagejlink</name> | ||
<properties> | ||
<kohlschutter.project.base.directory>${project.parent.basedir}</kohlschutter.project.base.directory> | ||
<mainClass>org.newsclub.net.unix.demo.jpackagejlink.DemoMainClass</mainClass> | ||
</properties> | ||
|
||
<description>junixsocket jpackage/jlink demo setup</description> | ||
|
||
<profiles> | ||
<profile> | ||
<id>jpackage</id> | ||
<activation> | ||
<property> | ||
<name>jpackage</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>jpackage-copy-main-jar</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>copy-resources</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory> | ||
${project.build.directory}/jpackage-app</outputDirectory> | ||
<resources> | ||
<resource> | ||
<directory> | ||
${project.build.directory}</directory> | ||
<includes> | ||
<include> | ||
${project.name}-${project.version}.jar</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.akman</groupId> | ||
<artifactId>jpackage-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>jpackage</goal> | ||
</goals> | ||
<configuration> | ||
<mainclass> | ||
${mainClass}</mainclass> | ||
<type>PLATFORM</type> | ||
<modulepath> | ||
<dependencysets> | ||
<dependencyset> | ||
<!-- add project output (module) | ||
to modulepath --> | ||
<includeoutput>true</includeoutput> | ||
<excludeautomatic>false</excludeautomatic> | ||
<includes> | ||
<include>glob:**/*.jar</include> | ||
</includes> | ||
</dependencyset> | ||
</dependencysets> | ||
</modulepath> | ||
<addmodules> | ||
<addmodule>java.base</addmodule> | ||
<!-- junixsocket-common --> | ||
<addmodule>org.newsclub.net.unix</addmodule> | ||
<!-- junixsocket-native-common --> | ||
<addmodule> | ||
com.kohlschutter.junixsocket.nativecommon</addmodule> | ||
<!-- this module --> | ||
<addmodule> | ||
org.newsclub.net.unix.demo.jpackagejlink</addmodule> | ||
</addmodules> | ||
<input> | ||
${project.build.directory}/jpackage-app</input> | ||
<mainjar> | ||
${project.name}-${project.version}.jar</mainjar> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
|
||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.akman</groupId> | ||
<artifactId>jpackage-maven-plugin</artifactId> | ||
<version>0.1.5</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</profile> | ||
|
||
<profile> | ||
<id>jlink</id> | ||
<activation> | ||
<property> | ||
<name>jlink</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.akman</groupId> | ||
<artifactId>jlink-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>jlink</goal> | ||
</goals> | ||
<configuration> | ||
<launcher> | ||
<command>junixsocket-jlink-demo</command> | ||
<mainmodule> | ||
org.newsclub.net.unix.demo.jpackagejlink</mainmodule> | ||
<mainclass> | ||
${mainClass}</mainclass> | ||
</launcher> | ||
<modulepath> | ||
<dependencysets> | ||
<dependencyset> | ||
<!-- add project output (module) | ||
to modulepath --> | ||
<includeoutput>true</includeoutput> | ||
<excludeautomatic>false</excludeautomatic> | ||
<includes> | ||
<include>glob:**/*.jar</include> | ||
</includes> | ||
</dependencyset> | ||
</dependencysets> | ||
</modulepath> | ||
<addmodules> | ||
<addmodule>java.base</addmodule> | ||
<!-- junixsocket-common --> | ||
<addmodule>org.newsclub.net.unix</addmodule> | ||
<!-- junixsocket-native-common --> | ||
<addmodule> | ||
com.kohlschutter.junixsocket.nativecommon</addmodule> | ||
<!-- this module --> | ||
<addmodule> | ||
org.newsclub.net.unix.demo.jpackagejlink</addmodule> | ||
</addmodules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
|
||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.akman</groupId> | ||
<artifactId>jlink-maven-plugin</artifactId> | ||
<version>0.1.11</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
<repositories> | ||
<repository> | ||
<id>sonatype.snapshots</id> | ||
<name>Sonatype snapshot repository</name> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url> | ||
<layout>default</layout> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.kohlschutter.junixsocket</groupId> | ||
<artifactId>junixsocket-core</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
</dependency> | ||
</dependencies> | ||
</project> |
11 changes: 11 additions & 0 deletions
11
junixsocket-demo-jpackagejlink/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* jpackage/jlink demo module | ||
*/ | ||
module org.newsclub.net.unix.demo.jpackagejlink { | ||
exports org.newsclub.net.unix.demo.jpackagejlink; | ||
|
||
requires java.base; | ||
|
||
requires org.newsclub.net.unix; | ||
requires com.kohlschutter.junixsocket.nativecommon; | ||
} |
20 changes: 20 additions & 0 deletions
20
...o-jpackagejlink/src/main/java/org/newsclub/net/unix/demo/jpackagejlink/DemoMainClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.newsclub.net.unix.demo.jpackagejlink; | ||
|
||
import org.newsclub.net.unix.AFUNIXSocket; | ||
|
||
/** | ||
* The entrypoint class for the jpackage or jlink demo binary. | ||
* | ||
* @author Christian Kohlschütter | ||
*/ | ||
public class DemoMainClass { | ||
/** | ||
* The entrypoint method for the jpackage or jlink demo binary. | ||
* | ||
* @param args The program arguments. | ||
*/ | ||
public static void main(String[] args) { | ||
// run a simple built-in selftest | ||
AFUNIXSocket.main(new String[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters