Skip to content
Build optimized Java runtimes in your browser!
Go Makefile Dockerfile
Branch: master
Clone or download
Latest commit 49d61fc Jan 19, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Reorganize project Jan 19, 2020
.travis.yml Install bsdtar dependency in travis ci Jan 15, 2020
Dockerfile Add PUT endpoint and general cleanup (closes #3) Jan 15, 2020
LICENSE Add license Jan 9, 2020
Makefile Reorganize project Jan 19, 2020
README.md Update readme Jan 19, 2020
adopt_openjdk.go Reorganize project Jan 19, 2020
go.mod Add PUT endpoint and general cleanup (closes #3) Jan 15, 2020
go.sum Improve JDK version handling Jan 9, 2020
jlink.go Reorganize project Jan 19, 2020
jlink_test.go Reorganize project Jan 19, 2020
maven_central.go Reorganize project Jan 19, 2020
util.go
util_test.go Reorganize project Jan 19, 2020

README.md

Build Status

jlink.online is a free microservice that builds custom Java runtimes on the fly.

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
You can’t perform that action at this time.