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

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

【maven 3.5.4 IDEA 2020】
学习《spring ioc基本使用》,使用maven方式构建spring项目。在test里面创建了一个main方法测试IOC的基本使用。但是运行时候报错:Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:exec (default-cli) on project spring_study2: Command execution failed.
在这里插入图片描述

解决一

参考博客

在maven生命周期框架中,test是用来做测试的,放入test的文件应该是test测试函数,即加了@Test的test函数,那为什么不用test函数来运行本过程呢?

public class MyTest {
    public static void main(String args[]) {
        //ApplicationContext:表示ioc容器
        //ClassPathXmlApplicationContext:表示从当前classpath路径中获取xml文件的配置
        //根据spring的配置文件来获取ioc容器对象
        ApplicationContext context = new ClassPathXmlApplicationContext("ioc.xml");
        Person person = (Person) context.getBean("person");
        System.out.println(person);
    }

}

改成:

public class MyTest {
    @Test
    public void Test() {
        //ApplicationContext:表示ioc容器
        //ClassPathXmlApplicationContext:表示从当前classpath路径中获取xml文件的配置
        //根据spring的配置文件来获取ioc容器对象
        ApplicationContext context = new ClassPathXmlApplicationContext("ioc.xml");
        Person person = (Person) context.getBean("person");
        System.out.println(person);
    }
}

然后在右侧Maven中,clean -> test 成功。

解决二

参考博客

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

仔细观察上面,发现其实是说插件exec-maven-plugin:3.0.0有问题。到本地Maven仓库去查看,可以找到地方:
在这里插入图片描述

先把本地仓库的mojo文件夹删除。然后在pom文件中添加插件:

<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>
             </configuration>
         </plugin>
     </plugins>
</build>

在这里插入图片描述

运行可能会出现中文乱码。此时在setting->maven->Runner->VM Options一栏中填入 -Dfile.encoding=gb2312。成功。

  • 19
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值