1. 程式人生 > >maven 打包時,jar should not point at files within the project directory 問題解決

maven 打包時,jar should not point at files within the project directory 問題解決

原來是web專案,想通過自動部署外掛把web專案打成war放到tomcat下 
在專案根部加了一個pom檔案 
但打包的時候卻報錯 
should not point at files within the project directory 

<dependency>  
        <groupId>antlr</groupId>  
        <artifactId>antlr</artifactId>  
        <version>2.7.7</version> 
        <scope>system</scope>  

        <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/antlr-2.7.7.jar</systemPath>  
    </dependency> 

解決方法之一

遵循以下用法:

用這種方式編寫你的依賴關係

<dependency><groupId>com.mylib</groupId><artifactId>mylib-core</artifactId><version>0.0.1</version></dependency>

然後新增maven-install-plugin

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-install-plugin</artifactId><version>2.5.2</version><executions><execution><id>install-external</id><phase>clean</phase><configuration>
<file>${basedir}/lib/mylib-core-0.0.1.jar</file><repositoryLayout>default</repositoryLayout><groupId>com.mylib</groupId><artifactId>mylib-core</artifactId><version>0.0.1</version><packaging>jar</packaging><generatePom>true</generatePom></configuration><goals><goal>install-file</goal></goals></execution></executions></plugin>

然後執行mvn clean、mvn install

解決方法之二:將Jar包存入本地倉庫,這樣將自動從你的倉庫中下載Jar包(推薦使用)