Maven添加本地Jar包


手動添加Jar包到我們的Maven項目中。

1、首先我在項目根目錄中創建一個lib文件夾,將jar包拷貝到lib文件夾下

 

2、然后我們在maven的pom.xml中配置

<groupId>org.wltea.analyzer</groupId>  
<artifactId>IKAnalyzer</artifactId>  
<version>2012FF_u1</version>  
<scope>system</scope>  
<systemPath>${project.basedir}/lib/IKAnalyzer2012FF_u1.jar  
</systemPath>  

 

 
eg.我在本地添加的源碼
  
      <!-- npl本地so -->
        <dependency>
            <groupId>com.netease.npl</groupId>
            <artifactId>npl</artifactId>
            <version>0.0.1</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/QASystem.jar
        </systemPath>
        </dependency>
        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>nlp</artifactId>
            <version>3.5.2</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/stanford-segmenter-3.5.2.jar
        </systemPath>
        </dependency>

 

3、這里的groupId和artifactId以及version都是可以隨便填寫的 ,scope必須填寫為system,而systemPath我們現在我們jar包的地址就可以了

4、最后我們必須在maven打包的過程中加入我們這個jar包。因為項目運行的時候需要這個Jar,並且我們得拷貝在WEB-INF/lib目錄下

<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>false</filtering>  
            <includes>  
                <include>**/*.jar</include>  
            </includes>  
        </resource>  
    </webResources>  
</configuration>  
<version>2.1.1</version> 

 

eg 我在本地添加的源碼
            <!-- 加載本地jar包 -->
            <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>false</filtering>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
                <version>2.1.1</version>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM