Maven pom 中如何引用 Jar 文件 – 热爱改变生活
我的GitHub GitHub |     登录
  • If you can't fly, then run; if you can't run, then walk; if you can't walk, then crawl
  • but whatever you do, you have to keep moving forward。
  • “你骗得了我有什么用,这是你自己的人生”
  • 曾有伤心之地,入梦如听 此歌

Maven pom 中如何引用 Jar 文件

Java sinvader 636℃ 0评论

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>

¥ 有帮助么?打赏一下~

转载请注明:热爱改变生活.cn » Maven pom 中如何引用 Jar 文件


本博客只要没有注明“转”,那么均为原创。 转载请注明链接:sumile.cn » Maven pom 中如何引用 Jar 文件

喜欢 (2)
发表我的评论
取消评论
表情

如需邮件形式接收回复,请注册登录

Hi,你需要填写昵称和邮箱~

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址