zoukankan      html  css  js  c++  java
  • Maven引入本地Jar包

    Maven引入本地Jar包

    2019.05.14 18:42:30字数 180阅读 3,579
    拷贝至项目根目录

    项目根目录即pom.xml文件所在的同级目录,可以在项目根目录下创建文件夹lib,如下图所示:

     
    配置pom.xml,依赖本地Jar

    配置Jar的dependency,包括groupId,artifactId,version三个属性,同时还要包含scope和systemPath属性,分别指定Jar包来源于本地文件,和本地文件的所在路径。

    POM文件里面可以引用一些内置属性(Maven预定义可以直接使用)  
    ${basedir} 项目根目录   
    ${version}表示项目版本;  
    ${project.basedir}同${basedir};  
    ${project.version}表示项目版本,与${version}相同;  
    ${project.build.directory} 构建目录,缺省为target  
    ${project.build.sourceEncoding}表示主源码的编码格式;  
    ${project.build.sourceDirectory}表示主源码路径;  
    ${project.build.finalName}表示输出文件名称;  
    ${project.build.outputDirectory} 构建过程输出目录,缺省为target/classes  
    
    //${project.basedir}
    <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>
    
    配置Maven插件将本地Jar打包进War中

    修改pom.xml文件

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.10</version>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>compile</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
                    <includeScope>system</includeScope>
                </configuration>
            </execution>
        </executions>
    </plugin>
    
    
    or 
    
    <resources>
                <!--表示把java目录下的有关xml文件,properties文件编译/打包的时候放在resource目录下 -->
                <resource>
                    <directory>${basedir}/src/main/java</directory>
                    <includes>
                        <include>**/*.properties</include>
                        <include>**/*.xml</include>
                    </includes>
                </resource>
                <resource>
                    <directory>${basedir}/src/main/resources</directory>
                </resource>
            </resources>
     
            <!--<!–引入本地jar包,就是plugins中的两个plugin(不知道哪个起作用,最好都引入)–> -->
            <plugins>
                <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>srcmainwebappWEB-INFlib</extdirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <webResources>
                            <resource>
                                <directory>${project.basedir}/lib</directory>
                                <targetPath>WEB-INF/lib</targetPath>
                                <filtering>true</filtering>
                                <includes>
                                    <include>**/*.jar</include>
                                </includes>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
        </plugins>
    
    

    OR

    在项目根目录下运行,通过mvn install:install-file命令安装lib目录中的jar包到本地Maven仓库。

    mvn install:install-file -DgroupId=com.aliyun.mns -DartifactId=aliyun-sdk-mns -Dversion=1.1.8 -Dfile=lib/aliyun-sdk-mns-1.1.8.jar -Dpackaging=jar -DgeneratePom=true
    

    在项目POM.xml文件中引用。

    <dependency>
        <groupId>com.aliyun.mns</groupId>
        <artifactId>aliyun-sdk-mns</artifactId>
        <version>1.1.8</version>
    </dependency>
  • 相关阅读:
    (双指针 二分) leetcode 167. Two Sum II
    (双指针) leetcode 485. Max Consecutive Ones
    (双指针) leetcode 27. Remove Element
    (String) leetcode 67. Add Binary
    (数组) leetcode 66. Plus One
    (N叉树 BFS) leetcode429. N-ary Tree Level Order Traversal
    (N叉树 递归) leetcode 590. N-ary Tree Postorder Traversal
    (N叉树 递归) leetcode589. N-ary Tree Preorder Traversal
    (N叉树 DFS 递归 BFS) leetcode 559. Maximum Depth of N-ary Tree
    (BST 递归) leetcode98. Validate Binary Search Tree
  • 原文地址:https://www.cnblogs.com/developer-ios/p/12069867.html
Copyright © 2011-2022 走看看