1.本地配置问题
在使用eclipse进行打包工程是报了以下错误,发现是从中央仓库读取jar包超时,但是发现本地仓库有这个jar包。
[ERROR] Plugin org.apache.maven.plugins:maven-war-plugin:2.2 or one of its dependencies could not be resolved: Could not transfer artifact org.apache.maven.plugins:maven-war-plugin:jar:2.2 from/to central (https://repo.maven.apache.org/maven2): GET request of: org/apache/maven/plugins/maven-war-plugin/2.2/maven-war-plugin-2.2.jar from central failed: Read timed out -> [Help 1]
后来才想到在setting.xml中定义了本地仓库的位置。解决问题就是取消本地setting.xml的自定义本地仓库配置,即使不定义,其也能找到(下图画圈)。
2.war包install问题
Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project First: Error assembling WAR: webxml attribute is requi red (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
在打war包时,如果缺少web.xml文件,会报以上错误,但有些情况有没有web.xml文件(即不是web工程),所以区别对待
1.需要web.xml文件的情况:
在pom.xml文件中指定web.xml的位置:
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <webResources> <resource> <directory>WebContent</directory> </resource> </webResources> </configuration> </plugin> </plugins>2.不需要web.xml文件的时候:
在pom.xml文件中,指定未扫描到web.xml文件时不做失败处理
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins>
3.maven继承问题
开发时,遇到工程要继承一个父工程,发现报以下错误。刚开始以为子工程配置错误,后来才知道,方向不对,努力白费。
Project build error: Invalid packaging for parent POM com.myd.cn:Parent:0.0.1-SNAPSHOT (E:\personal\Parent\pom.xml), must be "pom" but is "jar
细读错误,是子工程配置时,继承父工程的配置必须是POM文件,而不是jar,解决方案就是把父工程里的配置 改为POM文件
4.本地仓库不存在jar包(自己工程jar和第三方jar)
Missing artifact com.myd.cn:First:jar:0.0.1-SNAPSHOT:compile
如果是自己的jar,到本地仓库查下否存在(是否完成instal,未完成进入到工程根目录,进行mvn installl),然后与该工程POM.xml文件比较各个参数是否正确特使是groupID,artifactId,version,这三个很容易出错。
如果是第三方jar,查查本地是否存在,不存在则重新从中央仓库下载。