Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Maven references to customize jar package methods

Shulou Source: shulou.com Published: 2022-06-03 10:54:26 10月13日 Update

How to use Maven reference custom jar package way, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.

Maven references custom jar packages Overview

A third-party jar package is used in the project that is not available in the Maven central repository. How can Maven rely on it?

If the introduction is not good, the project will report:

java.lang.ClassNotFoundException exception

Import jar

Create a new lib directory under the src directory of the project, and then drag the jar package into this directory

Introducing dependencies in pom org.bouncycastle bcprov-jdk15on-154 1.0 system ${pom.basedir}/lib/bcprov-jdk15on-154.jar

Version is custom.

groupId is written according to the package hierarchy of jar package species

artifactId The name of the jar package I used directly

Add maven-dependency-plugin org.apache.maven.plugins maven-dependency-plugin 2.10 copy-dependencies compile copy-dependencies ${project.build.directory}/${project.build.finalName}/WEB-INF/lib system

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

environment briefing

Apache Maven 3.3.9

Java version: 1.7.0_80

OS name: "mac os x", version: "10.13.3"

Custom jar packages published to your own maven local repository

Using maven to build a project requires introducing custom packages into the project, and introducing the corresponding coordinates in the pom.xml of the project like maven. At this time, we have to upload the packages to the local repository ourselves. Here is how to operate:

① The jar package I want to upload is: ipdatabase-1.0.jar

② Find locally installed maven

Enter cmd into the bin directory at the location of the command line and enter the following command, hit Enter to start execution:

mvn install:install-file -Dfile=C:\Users\zhangsf\Desktop\ipdatabase.jar -DgroupId=zhang.jar -DartifactId=ipdatabase -Dversion=1.0 -Dpackaging=jar

of successes

One thing to note is that you need to place a setting.xml under the user's.m2 directory, otherwise you will package the jar package into the local default repository.

3 References in the project zhang.jar ipdatabase 1.0 Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Tags: Catalog project warehouse command help input way clear successful bad central middle use location content sibling name coordinates for this that is hierarchy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Microsoft Huawei MySQL macOS