Problem description:
There is a java maven web project that requires the introduction of a third-party package gdal.jar, but this package is packaged by itself. The package cannot be found in the maven central library. Therefore, I used the traditional method to copy this package to the directory of the project name: project name /src/main/webapp/WEB-INF/lib, and then introduce the gdal.jar package into the project project through config build path. For traditional java web projects, there is of course no problem doing this, but for maven projects, an error will be reported when the project is packaged (mvn install), and there will be incomplete file release problems during project debugging (debug on server): the project is in the webapp directory of tomcat, but the files inside are incomplete, and there will be a 404 error when accessed through the web.
Problem Solving:
The jar packages of the maven project are all managed through the maven mechanism. You can introduce the jar by yourself through the build path. There is no problem when writing the code, but problems will arise when debugging or publishing. The solution is to introduce the package into the project using maven. There are two solutions:
Upload the gdal.jar package to the company's maven private server, and then configure the path
If there is no maven private server, you can directly import the jar package through file and add a reference to the jar package in pom.xml
<dependency> <groupId>gdal</groupId> <artifactId>gdal</artifactId> <version>1.0.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/gdal.jar</systemPath> </dependency>Among them, project.basedir is a built-in property of maven, and there are 6 types of properties:
Built-in properties (predefined by Maven, users can use it directly)
${basedir} represents the project root directory, that is, the directory containing the pom.xml file;
${version} represents the project version;
${project.basedir} same as ${basedir};
${project.baseUri} represents the project file address;
${maven.build.timestamp} represents the project component start time;
${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. Its type can be referenced to java.text.SimpleDateFormat.
Two other ways
Method 1: Specify external lib in the compilation stage
<plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> <compilerArguments> <extdirs>lib</extdirs><!--Specify external lib--> </compilerArguments> </configuration> </plugin>
Method 2: Bring external jars into local maven repository
cmd enters the path where the jar package is located and executes the following command
The code copy is as follows:mvn install:install-file -Dfile=cloud.jar -DgroupId=com.hope.cloud -DartifactId=cloud -Dversion=1.0 -Dpackaging=jar
Introduce dependencies
<dependency> <groupId>com.hope.cloud</groupId> <artifactId>cloud</artifactId> <version>1.0</version> </dependency>
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.