Maven 引用本地jar包

2018-11-05  本文已影响0人  一颗北上广的心
  1. 项目中创建libs文件夹,与src同级即可


    image.png

    2.复制jar包到libs文件夹
    3.修改pom.xml 文件



<dependencies>

    <!--引入本地jar包-->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>alipay-sdk</artifactId>
        <version>1.0.20170324180803</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/libs/alipay-sdk-1.0.20170324180803.jar</systemPath>
    </dependency>

</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>

            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <encoding>UTF-8</encoding>
            </configuration>

        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <!--打包时,包含该jar包-->
                <webResources>
                    <resource>
                        <directory>${project.basedir}/libs</directory>
                        <targetPath>WEB-INF/lib</targetPath>
                        <filtering>false</filtering>
                        <includes>
                            <include>**/*.jar</include>
                        </includes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
</build>
    

Maven打包jar,且包含外部依赖jar包。

<?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>com.lmdtc</groupId>
  <artifactId>face</artifactId>
  <version>1.0-SNAPSHOT</version>
  <!--打包为Jar-->
  <packaging>jar</packaging>

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

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <!--同上,把jar包存在项目中-->
     <dependency>
        <groupId>com.arcsoft</groupId>
        <artifactId>face</artifactId>
        <version>2.0</version>
        <scope>system</scope> <!--指定system scope,下方编译的时候也包含system的jar包-->
        <systemPath>${project.basedir}/src/lib/arcsoft-sdk-face-2.2.0.1.jar</systemPath>
     </dependency>

  </dependencies>

  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- 指定该Main Class为全局的唯一入口 -->
                    <mainClass>com.lmdtc.FaceEngineTest</mainClass>
                    <layout>ZIP</layout>
                    <!--包含system jar包,上方把外部的jar已导入且声明为system,此处即可打包进来-->
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中 -->
                        </goals>
                    </execution>
                </executions>
            </plugin>

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

上一篇 下一篇

猜你喜欢

热点阅读