Problem
I’m working on a Java Spring Application. I'm able to run this application via Run command of Intellij and it works without any problems. However, even if it starts with mvn spring-boot:run
command, it fails during runtime with unnamed module
error. The provided dependency can not initiated its classes.
The projects Java version is 11.
SOLVED Thanks to https://stackoverflow.com/users/10870817/sot JDK setting in Intellij was different from JDK in JAVA_HOME. It worked after fixing JAVA_HOME.
Error
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed;
nested exception is java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: Provider com.sun.xml.ws.spi.ProviderImpl could not be instantiated] with root cause
java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class
java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module
Details:
This application depends on a package which is provided by an external party as jar file together with its dependencies:
└── lib
├── ProvidedDependency.jar
├── ItsDependency1.jar
└── ItsDependency2.jar
I installed externally provided packages to my local maven repository:
mvn install:install-file -Dfile=lib/ProvidedDependency.jar -DgroupId=com.external -DartifactId=provided-dep -Dversion=1.0 -Dpackaging=jar
mvn install:install-file -Dfile=lib/ItsDependency1.jar -DgroupId=com.external1 -DartifactId=first-dep -Dversion=1.0 -Dpackaging=jar
mvn install:install-file -Dfile=lib/ItsDependency2.jar -DgroupId=com.external2 -DartifactId=second-dep -Dversion=1.0 -Dpackaging=jar
I added these dependencies to my pom.xml:
<dependency>
<groupId>com.external</groupId>
<artifactId>provided-dep</artifactId>
<version>1.0</version>
</depedency>
<dependency>
<groupId>com.external1</groupId>
<artifactId>first-dep</artifactId>
<version>1.0</version>
</depedency>
<dependency>
<groupId>com.external2</groupId>
<artifactId>second-dep</artifactId>
<version>1.0</version>
</depedency>
Moreover, I already added my local repository into pom.xml as well:
<repositories>
<repository>
<id>local-repo</id>
<url>file://{user.home}/.m2/repository
</repository>
</repositories>
Morever, org.spring.framework.boot is added as parent to pom.xml, too:
<parent>
<groupId>org.spring.framework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
</parent>
Summary
Since Spring Application runs via Intellij's Run, but I need to run it via command line, so that it can be containerized.
What could be root cause, is there anything I'm missing during execution or building the project?
I'm quite sure that your JDK setting in Intellij is different from JDK in JAVA_HOME. Make sure both are the same