Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jlink spring boot

Tags:

I have a simple hello world spring 2 boot app, which runs with full JDK 13. Now I am trying to get this to run with a custom JRE using spring boot.

In past when I have need external jars, I have run jdeps -s json-20190722.jar to see what modules I need.

$jdeps -s json-20190722.jar 
json-20190722.jar -> java.base

But when I do this with Spring I get

$jdeps -s spring-boot-2.2.4.RELEASE.jar
spring-boot-2.2.4.RELEASE.jar -> java.base
spring-boot-2.2.4.RELEASE.jar -> java.desktop
spring-boot-2.2.4.RELEASE.jar -> java.logging
spring-boot-2.2.4.RELEASE.jar -> java.management
spring-boot-2.2.4.RELEASE.jar -> java.naming
spring-boot-2.2.4.RELEASE.jar -> java.sql
spring-boot-2.2.4.RELEASE.jar -> java.xml
spring-boot-2.2.4.RELEASE.jar -> not found

It also fails when I do

$ jdeps --generate-module-info . spring-boot-2.2.4.RELEASE.jar | more
Missing dependence: ./spring.boot/module-info.java not generated
Error: missing dependencies
spring.boot
   org.springframework.boot.Banner                    -> org.springframework.core.env.Environment           not found
   org.springframework.boot.BeanDefinitionLoader      -> groovy.lang.Closure                                not found

What am I missing here?

Thank you

like image 668
ghjghgkj Avatar asked Jan 22 '20 23:01

ghjghgkj


People also ask

What is Jlink used for?

Jlink is a Java command line tool that is used to generate a custom Java runtime environment (JRE). You can use your customized JRE to run Java applications. Using jlink, you can create a custom runtime environment that only includes the relevant class file.

Does spring boot work with Java 11?

What Java version does the latest Spring Boot support? Spring Boot 2.7. 1 (and therefore the latest Spring Framework 5.3. 22) supports Java 17 while also remaining compatible with Java 11 and 8.

What are modules in spring boot?

The application module is the main module of the project. It contains the application class in which the main method is defined that is necessary to run the Spring Boot Application. It also contains application configuration properties, Controller, views, and resources.


1 Answers

You need also all your dependencies and point it in class path option.

$jdeps -R -s --multi-release 13 -cp 'path-to-dependencies/*' your-app.jar

You can find all dependencies if you extract your fat jar (see The Executable Jar File Structure):

 jar -xvf your-jar-file.jar

Or retrieve them with Gradle and custom task:

task copyDependencies(type: Copy) {
    from configurations.default
    into 'build/libs/dependencies'
}
like image 147
Denis.E Avatar answered Sep 18 '22 11:09

Denis.E