Maven pom中如何引用Jar文件

Pom中如何引用Jar文件

pom.xml文件中有一个plugins标签,在这个标签中添加一个plugin
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webResources>
            <resource>
                <directory>${project.basedir}/libs</directory>
                <targetPath>WEB-INF/lib</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>
并在build标签下添加
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>7</source>
            <target>7</target>
        </configuration>
    </plugin>
</plugins>
在根目录下添加一个libs文件夹,将jar文件复制到目录下 假设libs目录下有javacsv-2.1.jar文件
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>javacsv-2.1</artifactId>
    <version>2.1</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/javacsv-2.1.jar</systemPath>
</dependency>
假设libs目录下有xercesImpl.jar文件
<dependency>
    <groupId>com.aliyun</groupId>   //随便写
    <artifactId>xercesImpl</artifactId>
    <version>2.4.0</version>        //随便写
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/xercesImpl.jar</systemPath>
</dependency>
贴一份完整的以防粘贴的少了
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>net.sumile.fileComparison</groupId>
    <artifactId>FileComparison</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>FileComparison</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.0.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>4.3.11.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.0.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.0.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.0.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.3</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>apache-ant-1.8.2</artifactId>
            <version>1.8.2</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/apache-ant-1.8.2.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>dom4j-1.6.1</artifactId>
            <version>1.6.1</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/dom4j-1.6.1.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>javacsv-2.1</artifactId>
            <version>2.1</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/javacsv-2.1.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>ojdbc6-11</artifactId>
            <version>11</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/ojdbc6-11.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>poi-3.9</artifactId>
            <version>3.9</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/poi-3.9.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>poi-ooxml-3.9</artifactId>
            <version>3.9</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/poi-ooxml-3.9.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>poi-ooxml-schemas-3.9</artifactId>
            <version>3.9</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/poi-ooxml-schemas-3.9.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>super-csv-2.4.0</artifactId>
            <version>2.4.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/super-csv-2.4.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.4.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/xercesImpl.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>xmlbeans-2.3.0</artifactId>
            <version>2.3.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/xmlbeans-2.3.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>FileComparison</finalName>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.20.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <webResources>
                            <resource>
                                <directory>${project.basedir}/libs</directory>
                                <targetPath>WEB-INF/lib</targetPath>
                                <includes>
                                    <include>**/*.jar</include>
                                </includes>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>7</source>
                    <target>7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

深入理解Java虚拟机 笔记(2018.06.19-23) 2018-06-24
深入理解 Java 虚拟机 笔记 (2018.06.26-30) 2018-06-30

评论区