当前位置: 首页 > 图灵资讯 > 技术篇> Maven常见异常及解决方法

Maven常见异常及解决方法

来源:图灵教育
时间:2023-06-11 09:10:46

1.ReasonPhrase: Forbidden:

|--- 1.注意用户权限和角色role的设置,一般没有权限就会被禁止。

2.Failed to collect dependencies:

|--- 1.parent项目,即package是pom的项目,需要先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和第五条一样.添加plugin多定义的xml

<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)

|---- 1.添加以下插件,主要是因为没有指定web.位于pomml的xml.加入xml

<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.缺少Springaspects的jar包,在pomm.引入xml

|---- 2.请注意,还应导入Spring的ORM框架,因为无法将Beanager和hibernate注入txmanager和hibernate

|---- 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.由于Nexus中央仓库在Maven中使用,deploy的设置没有设置好,但在项目的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

|-pomm缺少jstl包.xml加入

<dependency>     <groupId>jstl</groupId>     <artifactId>jstl</artifactId>     <version>1.2</version></dependency>

14. SSH和SpringMVC框架在使用IDE自带的tomcat管理时,需要添加Servletet.在providee中设置api和他的声明周期

<dependency>     <groupId>javax.servlet</groupId>     <artifactId>jsp-api</artifactId>     <version>2.0</version>     <scope>provided</scope></dependency>

15.overlay [ id com.六dianedu: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>