Popularity
2.0
Stable
Activity
6.2
Declining
20
2
0

Programming language: Go
Tags: Distribution     Projects    

jlink.online alternatives and similar libraries

Based on the "Distribution" category

Do you think we are missing an alternative of jlink.online or a related project?

Add another 'Distribution' Library

README

:tada: This project is now a member of AdoptOpenJDK! :tada:

Motivation

As of Java 9, the JDK now includes a nifty tool called jlink that can build optimized runtimes for modular Java applications. Using an optimized runtime is a good idea when deploying to a production environment (due to space savings and a slightly reduced attack surface) or when bundling a platform-specific runtime to distribute with your application.

This project is basically a wrapper for Java's jlink utility that makes it faster and easier to build custom Java runtimes. Just specify what modules you need in an HTTP request and jlink.online will automatically download the appropriate JDK, run jlink to produce a custom runtime, then return the compressed runtime in the response body.

Usage Examples

Download the latest Java 13 release for Linux x64 (contains java.base only)

https://jlink.online/x64/linux/13

Download the latest Java 13.0.1 release for Linux x64 (contains java.desktop and jdk.zipfs)

https://jlink.online/x64/linux/13.0.1?modules=java.desktop,jdk.zipfs

Download the latest Java LTS release for Windows x64 (also works with ea and ga)

https://jlink.online/x64/windows/lts

Download the latest Java GA release (OpenJ9 JVM implementation)

https://jlink.online/x64/linux/ga?implementation=openj9

Download the latest Java 12 release for Linux S390X (big endian)

https://jlink.online/s390x/linux/12?endian=big

Download a runtime in a Dockerfile

# If you do 'FROM openjdk' then you'll get a full runtime
FROM alpine:latest

# Install dependencies
RUN apk add curl

# Install custom runtime
RUN curl -G 'https://jlink.online/x64/linux/lts' \
  -d modules=java.base \
  | tar zxf -

# Install application
# ...

Upload your application's module-info.java (experimental)

Suppose your application has the following module definition:

module com.github.example {
    requires org.slf4j;
}

Then to build a custom runtime containing your dependencies, you can send a POST request containing the contents of your module-info.java:

curl --data-binary @com.github.example/src/main/java/module-info.java \
  'https://jlink.online/x64/linux/lts?artifacts=org.slf4j:slf4j-api:2.0.0-alpha1' \
  --output app_runtime.tar.gz

The artifacts parameter is a comma-separated list of the Maven Central coordinates of your dependencies. This is required to know what versions to include in your runtime.

Unfortunately this can't work for dependencies that are automatic modules (because automatic modules don't specify their dependencies).

API Reference

Parameter Acceptable Values Default
arch x64, x32, ppc64, s390x, ppc64le, aarch64, arm32 N/A
os windows, linux, mac, solaris, aix N/A
endian little, big N/A
implementation hotspot, openj9 hotspot
version A Java version number greater than 9, ga (latest general-availability release), ea (latest early-access release), lts (latest LTS release) N/A
modules Any comma-separated list of JDK modules java.base

Not all combinations of OS + architecture + version are available. Please check the AdoptOpenJDK archive to see if your target platform is supported.

Future Improvements

Use caching to make it faster

The only files being cached right now are the full AdoptOpenJDK runtimes required by jlink. Caching the generated runtimes as well would greatly improve the average request time.

Allow Maven Central modules

There's no reason to limit this to JDK modules. It would be nice to upload a module-info.java and get back an image containing all of the application's dependencies.

Credits

Thanks to the following projects for making this project easier:

  • AdoptOpenJDK - for providing the JDK builds
  • gin - for serving HTTP requests
  • jlink - for minimizing the runtime images