Maven常見異常解決《二》
阿新 • • 發佈:2017-05-19
inf 項目 orb solved update nsf nap ips transfer 下面是一些Maven工程的常見異常:
1.ReasonPhrase: Forbidden:
|--- 1.註意用戶的權限以及角色role的設置,通常是沒有權限才會被禁止的。
2.Failed to collect dependencies:
|--- 1.須要把parentproject,也就是package是pom的那個project先install一下。或者deploy
|--- 2.須要註意在設置的<profile>工廠裏面能否夠訪問,假設直接訪問public分組,那麽就要檢查public分組是否加入了自己設置的工廠
3.child module ....pom.xml does not exist:
|---- 1.註意module的名稱是否正確,有時候命名問題會導致找不到項目的
|---- 2.註意一開始項目命名的規則問題
4.Cannot detect Web Project version. Please specify version of Web Project through <version> configuration property of war plugin. E.g.: <plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <version>3.0</version> </configuration> </plugin>
|---- 1.和第五條一樣在pom.xml增加plugin多的定義就可以
|---- 1.增加下面插件引用:主要是由於沒有指定web.xml的位置,在pom.xml中增加
7.Failed to clean project: Failed to delete F:\project\Stest......\target |---- 1.又一次使用命令clean一遍就可以 8.The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory |---- 1.註意:jsp-api的依賴的scope一定要provide。即不打包進去。否則會和tomcat沖突
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<version>3.0</version>
</configuration>
</plugin>
5.Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project marer-test-weixin: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<version>3.0</version>
<webXml>WebRoot\WEB-INF\web.xml</webXml><!-- 這裏指定位置 -->
</configuration>
</plugin>
6.javax.servlet.jsp.PageContext cannot be resolved to a type
|---- 1.這是由於沒有引入jsp-api引發的問題,在pom.xml引入:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
</dependency>
7.Failed to clean project: Failed to delete F:\project\Stest......\target |---- 1.又一次使用命令clean一遍就可以 8.The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory |---- 1.註意:jsp-api的依賴的scope一定要provide。即不打包進去。否則會和tomcat沖突
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
9.java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld
|---- 1.缺少Spring的aspects的jar包,在pom.xml中引入
|---- 2.註意Spring的ORM框架也要導入,讀取配置文件失敗,原因是由於不能給txManager和hibernate註入Bean
|---- 3.註意2:我在上面已經用全局變量指定了Spring的<version>...</version>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
10.Spring註入失敗,【在action中註入service的對象或在service中註入dao對象】發生空指針異常
|---- 1.首先須要確定你的配置文件是否起了作用:applicationContext.xml是否已經在使用了
|---- 2.確定全部的properties文件是正確無誤的
|---- 3.確定是否使用了struts2-spring-plugin依賴:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
</dependency>
11.-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
|---- 1.eclipse中使用maven插件的時候,執行run as maven build的時候報錯。是由於JDK有問題
|---- 2.假設確定自己的Eclipse中的Window->Preference->Java->Installed JREs 設置好相應的JDK環境
|---- 3.在Default VM arguments中增加:-Dmaven.multiModuleProjectDirectory=$M2_HOME
12.Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project jiabo-motor:Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepositor
|--- 1.deploy的設置沒有設置好,這是由於在Maven中使用了Nexus中央倉庫。可是在項目的pom.xml中沒有設置
|--- 2.增加例如以下設置:【自己之前自己定義的deploy的地址】
<!-- 設置deploy的地址 -->
<distributionManagement>
<repository>
<id>user-release</id>
<name>user release resp</name>
<url>http://localhost:8081/nexus/content/repositories/user-release/</url>
</repository>
<snapshotRepository>
<id>user-snapshot</id>
<name>user snapshot</name>
<url>http://localhost:8081/nexus/content/repositories/user-snapshot/</url>
</snapshotRepository>
</distributionManagement>
13. The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
|---缺少jstl的包,在pom.xml增加
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
14. SSH和SpringMVC框架在使用IDE自帶的tomcat管理的情況下,須要增加Servlet.api以及設置他的聲明周期為provide
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
15.overlay [ id com.6dianedu:liudian-web] is not a dependency of the project.
|---將須要打包的項目依賴進來,增加<type>war</type>屬性
16.ArtifactDescriptorException: Failed to read artifact descriptor for org.apache.shiro:shiro-core:jar:${shiro.version}: ArtifactResolutionException: Failure to transfer org.apache.shiro:shiro-core:pom:${shiro.version} from http://localhost:8081/nexus/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.shiro:shiro-core:pom:${shiro.version} from/to nexus
這是因為在pom.xml裏面的依賴使用了定義的變量${shiro.version},可是卻沒有在<properties>...</properties>中進行定義,僅僅要在pom.xml加上定義就可以
<properties>
<shiro.version>1.2.3</shiro.version>
</properties>
tips:並不排除一些電腦運行太慢原因造成的問題,多細心,用集成軟件編寫代碼時候不要盲目相信提供的解決方法!
Maven常見異常解決《二》