英文:
ClassNotFoundException for a class available in one of the jar from BOOT-INF/lib
问题
我有2个Spring Boot Maven项目。第一个项目使用maven-jar-plugin
创建了一个额外的JAR文件,pom.xml
中的插件部分如下所示。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>beans</classifier>
<includes>
<include>**/models/*</include>
<include>**/exceptions/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
这会创建一个名为 "sample-0.0.1-SNAPSHOT-beans.jar" 的文件,并将其上传为构件。
第二个项目引用上述JAR文件作为依赖项。第二个项目的pom.xml
包含以下内容:
<dependency>
<groupId>com.abc</groupId>
<artifactId>sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>beans</classifier>
</dependency>
第二个项目的构建输出是一个可执行的JAR文件。当我解压这个JAR文件时,其中包含了 BOOT-INF\lib
目录,其中包含了 sample-0.0.1-SNAPSHOT-beans.jar
。
然而,当我执行第二个项目时,它抛出以下异常:
java.lang.TypeNotPresentException: Type com.sample.models.AData not present
at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
...
我真的不知道缺少什么,请帮我解决这个问题!
英文:
I have 2 spring-boot maven projects. The first project creates an extra jar using maven-jar-plugin, the pom.xml plugin part is as below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>beans</classifier>
<includes>
<include>**/models/*</include>
<include>**/exceptions/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
This creates "sample-0.0.1-SNAPSHOT-beans.jar" and also upload as artifact.
The 2nd project is referring the above jar as a dependency. The pom.xml of 2nd project contains
<dependency>
<groupId>com.abc</groupId>
<artifactId>sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>beans</classifier>
</dependency>
The build output of the 2nd project is an executable jar. when I explode this jar, it has BOOT-INF\lib and that lib contains sample-0.0.1-SNAPSHOT-beans.jar.
However, when I execute 2nd project, it throws
java.lang.TypeNotPresentException: Type com.sample.models.AData not present
at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at java.base/sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at java.base/sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
at java.base/sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at java.base/sun.reflect.generics.repository.ClassRepository.computeSuperclass(ClassRepository.java:104)
at java.base/sun.reflect.generics.repository.ClassRepository.getSuperclass(ClassRepository.java:86)
at java.base/java.lang.Class.getGenericSuperclass(Class.java:955)
at org.springframework.core.ParameterizedTypeReference.<init>(ParameterizedTypeReference.java:52)
at com.sample.util.DataCacheUtil$1.<init>(DataCacheUtil.java:50)
at com.sample.util.DataCacheUtil.getAData(DataCacheUtil.java:50)
I really do not get what is missing here, please help me out!
专注分享java语言的经验与见解,让所有开发者获益!
评论