There are two ways to use a local jar package in a MAVEN project:
1. Use System scope
<dependencies>
<dependency>
<groupId>org.richard</groupId>
<artifactid >my-jar</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/my-jar.jar</systemPath>
</dependency>
</ Dependencies>
Packages introduced by system scope will not be included when packaged with Jar-with-dependencies, and you can use resources to bring local packages into jar-with-dependencies
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <executions> <execution>
<id>make-assembly</id> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <descri Ptorrefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descripto
Rrefs> <finalName>xxx-jar-with-dependencies</finalName> </configuration>
</execution> </executions> </plugin> </plugins> <resources>
<resource> <targetPath>lib/</targetPath> <directory>lib/</directory>
<includes> <include>**/my-jar.jar</include> </includes> </resource> </resources > </build>
In the generated Xxx-jar-with-dependencies.jar, the Lib directory and the My-jar.jar are included, and can be found at execution time.
Sometimes this method can be effective, such as jdbcdriver in the statement class.forname ("xxx.") Driver ") will say that the class can not be found, in the following two ways.
2. Install Jar Pack into local repository
MVN Install:install-file-dfile=my-jar.jar-dgroupid=org.richard-dartifactid=my-jar-dversion=1.0-dpackaging=jar
3. Add in Project Repository, do not run the MVN install:install-file command when executing on a new machine
<repository>
<id>in-project</id>
<name>in project repo</name>
<url >file://${project.basedir}/lib</url>
</repository>
<dependency>
<groupid >org.richard</groupId>
<artifactId>my-jar</artifactId>
<version>1.0</ Version>
</dependency>
Your jar package and path must be in strict accordance with the format:
/groupid/artifactid/version/artifactid-verion.jar
In this case: Lib/org/richard/my-jar/1.0/my-jar-1.0.jar