Maven's SNAPSHOT dependency, cannot find a class solution

 

Phenomenon:

A SNAPSHOT version of the dependency is added to maven's pom.xml dependency configuration:

<dependency>
			<groupId>com.yame.ecpark</groupId>
			<artifactId>ecpark-cache-driver</artifactId>
			<version>1.6.3-SNAPSHOT</version>
		</dependency>

 When the program runs to the relevant code, it reports an exception that the class cannot be found:


 

This Client class is obviously in ecpark-cache-driver-1.6.3-SNAPSHOT.jar, and in the packaged lib folder, it also exists

jar包:


 

Why do I still report the exception that the class cannot be found? ?

 

 

 

 

After thinking about it for a long time, I was fortunate to have the advice of an expert colleague, decompile the jar file packaged by maven, and look at the dependency path of the jar file inside:


 Mouth open! ! ! !

 

Here, Class-Path: ./lib/ecpark-cache-driver-1.6.3-20180412.072035-2.jar lib, written very clearly, the dependent ecpark-cache-driver version has the time and date version, but in the lib package Yes , there is only one ecpark-cache-driver-1.6.3-SNAPSHOT.jar, and they are not the same file, so it is no wonder that the Client class cannot be found.

Once you know the cause of the problem, it's easy to do.

When packaging maven, specify <useUniqueVersions>false</useUniqueVersions> , such as:

 

<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
							<mainClass>com.yame.Application</mainClass>
							<useUniqueVersions>false</useUniqueVersions>  
						</manifest>
						<manifestEntries>
							<Class-Path>./</Class-Path>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>

 

In this way, when packing,

MANIFEST.MF中的Class-Path: lib/ecpark-cache-driver-1.6.3-20180412.072035-2.jar

Convert to Class-Path: /lib/ecpark-cache-driver-1.6.3-SNAPSHOT.jar

At the same time, there is also ecpark-cache-driver-1.6.3-SNAPSHOT.jar  under the lib folder , so that the exception that the class cannot be found will not be reported.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326074875&siteId=291194637