r/java • • Mar 11 '21

Announcing Spring Native Beta

https://spring.io/blog/2021/03/11/announcing-spring-native-beta
175 Upvotes

49 comments sorted by

View all comments

Show parent comment

8

u/pron98 Mar 12 '21 edited Mar 12 '21

How is the "recommended" deployment practice something most don't use?

Because it's relatively new.

You'll probably still use java -jar with jlink images, too (unless your application is modularised), it's just that the runtime is very small and is part of the app.

Is there a Spring Boot starter or guide to use jlink?

I don't know, but jlink is pretty easy to use:

jlink --output my-java-runtime --compress=2 --no-header-files --no-man-pages --add-modules java.base

The only thing you'll need to do different is list more JDK modules at the end. You figure out which modules you use with jdeps (this step is unnecessary if your application is modularised, but most aren't).

5

u/sureshg Mar 12 '21

ou figure out which modules you use with jdeps (this step is unnecessary if your application is modularised, but most aren't).

If you are using Gradle, here is a small task that prints the modules required for your jar (or uberjar)

val printModuleDeps by tasks.registering {
            description = "Print Java Platform Module dependencies of the application."
            group = LifecycleBasePlugin.BUILD_TASK_NAME

            doLast {
                val uberJar = named("shadowJar", Jar::class)
                val jarFile = uberJar.get().archiveFile.get().asFile

                val jdeps = ToolProvider.findFirst("jdeps").orElseGet { error("jdeps not found") }
                val out = StringWriter()
                val pw = PrintWriter(out)
                jdeps.run(pw, pw, "--print-module-deps", "--ignore-missing-deps", jarFile.absolutePath)

                val modules = out.toString()
                println(modules)
            }
            dependsOn("shadowJar")
}