Maven project refers to the method of external jar package

Problem Description:

There is a Java Maven web project, which needs to introduce a third-party package GDAL Jar, but the package is packaged by itself, and the package cannot be found in the Maven central library. Therefore, I copy the package to the directory of project name \ SRC \ main \ webapp \ WEB-INF \ Lib in the traditional way, and then use config build path to download the GDAL The jar package is introduced into the project. For traditional Java Web projects, this is certainly no problem, but for Maven projects, errors will be reported when the project is packaged (MVN install), and incomplete file distribution will also occur during project debugging (debug on server): the project exists in the webapp directory of tomcat, but the files are incomplete, and 404 errors will occur when accessing through the web.

Problem solving:

The jar packages of Maven project are managed through Maven mechanism. You can import jars through build path. There is no problem when writing code, but there will be problems when debugging or publishing. The solution is to introduce the package into the project in the way of Maven. There are two solutions:

Add GDAL Upload the jar package to the Maven private server of the company, and then configure the path

If there is no Maven private server, you can directly import the jar package through a file in POM. Com Add a reference to the jar package in XML

Including project Basedir is a built-in attribute of Maven. There are 6 types of attributes:

Built in attributes (predefined by maven, which can be used directly by users)

${basedir} represents the root directory of the project, which contains POM Directory of XML files;

${version} indicates the project version;

${project. Basedir} is the same as ${basedir};

${project. Baseuri} indicates the project file address;

${Maven. Build. Timestamp} indicates the start time of the project component;

${Maven. Build. Timestamp. Format} represents the display format of the attribute ${Maven. Build. Timestamp}. The default value is yyyymmdd HHMM. Its format can be customized, and its type can refer to Java text. SimpleDateFormat。

Two other ways

Method 1: specify external lib at compile time

Method 2: import external jars into the local Maven warehouse

CMD enter the path where the jar package is located and execute the following command

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>