Maven references custom jar package

Summary

In the project, a third-party jar package that is not available in Maven's central warehouse is used. How to rely on it in Maven?
If the introduction is not good, the following will be reported when starting the project:

java.lang.ClassNotFoundException exception

Import jar

In the src directory of the project, create a new lib directory, and then drag the jar package to this directory

Introducing dependency into pom

<dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on-154</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${pom.basedir}/lib/bcprov-jdk15on-154.jar</systemPath>
        </dependency>
  • version is custom
  • groupId is written according to the package level of jar package type
  • artifactId the name of the jar package I used directly

Add Maven dependency plugin

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
                            <includeScope>system</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

After packing, in the jar package, go to the directory / WEB-INF/lib, and you can see that bcprov-jdk15on-154.jar has been typed in.

Environmental description

  • Maven version: Apache Maven 3.3.9
  • Java version: 1.7.0_80
  • OS name: "mac os x", version: "10.13.3"

Tags: Maven Java Apache Mac

Posted on Sun, 05 Apr 2020 09:23:37 -0700 by GreenSmurf