解决Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:exec (default-cli) on project

使用maven练习spring ioc练习时,
在test文件夹中编写测试类代码用main方法失败
代码如下图所示–

  public static void main(String[] args) {

            UserService userService = new UserServiceImpl();
            userService.getUser();
    }
}

方法一
将其改为以下代码即可

public class myTest {
    @Test
            public void test(){
        UserService userService = new UserServiceImpl();
        userService.getUser();
        //默认获取用户的数据
    }
}

方法二
重新看一下原先用main方法的报错信息为

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:exec (default-cli) on project 01-spring-ioc: Command execution failed.

找到maven中的本地仓库,然后依据\org\codehaus\mojo\mojo-parent找到mojo文件夹,将其删除

D:\ maven中的本地仓库\org\codehaus\mojo\mojo-parent

删除mojo文件后,在idea项目中找到pom.xml ,配置如下代码

<build>
     <plugins>
         <plugin>
             <groupId>org.codehaus.mojo</groupId>
             <artifactId>exec-maven-plugin</artifactId>
             <version>1.6.0</version>
             <executions>
                 <execution>
                     <goals>
                         <goal>java</goal>
                     </goals>
                 </execution>
             </executions>
             <configuration>
                 <classpathScope>test</classpathScope>
                 <!--<mainClass></mainClass>-->
             </configuration>
         </plugin>
     </plugins>
</build>

如果此时导入插件的版本号等信息标红,不用管它,直接去运行test目录下的main方法,maven会自己下载插件
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值