1. Overview
In daily development, some Jar packages are not included in Maven's central warehouse for various reasons, so they have to be added using local introduction.
2. Copy to the project root directory
The project root directory is the same as the directory where the pom.xml file is located. You can create a folder lib in the project root directory, as shown in the figure below:
These 4 Jar packages are required to identify web encoding.
3. Configure pom.xml and rely on local Jar
Configure Jar's dependency, including groupId, artifactId, and version, and also includes scope and systemPath attributes, specifying the local file originating from the local file and the path where the local file is located.
<!-- ###################################################################################### --><dependency> <groupId>cpdetector</groupId> <artifactId>cpdetector</artifactId> <version>1.0.10</version> <scope>system</scope> <systemPath>${basedir}/lib/cpdetector_1.0.10.jar</systemPath></dependency><dependency> <groupId>antlr</groupId> <artifactId>antlr</artifactId> <version>2.7.4</version> <scope>system</scope> <systemPath>${basedir}/lib/antlr-2.7.4.jar</systemPath></dependency><dependency> <groupId>chardet</groupId> <artifactId>chardet</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${basedir}/lib/chardet-1.0.jar</systemPath></dependency><dependency> <groupId>jargs</groupId> <artifactId>jargs</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${basedir}/lib/jargs-1.0.jar</systemPath></dependency>where ${basedir} refers to the project root path
4. Configure the Maven plugin to package the local Jar into War
After performing the above configuration, you can already introduce the class in the Jar package when writing the code. However, when packaging, because scope=system, the Jar package will not be packaged into the war package by default, and all needs to be packaged through plug-ins.
Modify the pom.xml file and add the following code under the plugins tag
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependent-plugin</artifactId> <version>2.10</version> <executions> <execution> <id>copy-dependents</id> <phase>compile</phase> <goals> <goal>copy-dependents</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory> <includeScope>system</includeScope> </configuration> </execution> </executions></plugin> In this way, the war package that is printed will contain locally introduced jar dependencies.
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.