I'm trying to create a simple Spring Boot application and run it with Java Modules on the latest Java version.
I have created a Main class:
package org.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Main {
public static void main(final String[] args) {
System.out.println("Module: " + Main.class.getModule());
SpringApplication.run(Main.class, args);
}
}
And a module-info.java
:
module spring.jpms {
requires spring.core;
requires spring.boot;
requires spring.boot.autoconfigure;
requires spring.context;
requires spring.beans;
opens org.example to
spring.core,
spring.beans,
spring.context;
}
When I run the Main class using an IDE generated command with module path, it works fine, the name of my application module printed out.
Module: module spring.jpms
...
When I run my application using mvn spring-boot:run
or java -jar <target>.jar
, the application is executed in the class-path mode. The module name is "unnamed":
...
Module: unnamed module @7923f745
...
I would like to know if there is a way to run a .jar file built by the Spring Boot Maven plugin with Java Modules, that is so the .jar files are loaded via module-path
See the complete example here: https://github.com/agavrilov76/spring-jpms
Just as an update, I can confirm that it is now possible with spring-boot-starter-parent:3.3.0
to execute the application with only a command such as:
mvn spring-boot:run
Alternatively, one can at the same time create an executable using:
mvn clean package
and execute as(sample) :
java -jar target/jpms-spring-0.0.1-SNAPSHOT.jar
Here is a reference: https://github.com/namannigam/jpms-spring
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With