当前位置:   article > 正文

报错:Failed to execute goal org.codehaus.mojo:........快速解决!

org.codehaus.mojo

解决:Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:exec (default-cli) on project spring_aop: Command execution failed.的问题


出现如下问题:

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

解决方案一:这种情况下,我是将用main方法执行程序,改为使用单元测试@Test

~之前是这样的:用的是main运行

public class MyTest {
    public static void main(String[] args) {
    
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        //动态代理代理的是接口
        UserService userservice = (UserService) context.getBean("userservice");

        userservice.add();
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

~改成了:用@Test

import com.niuyun.service.UserService;
import com.niuyun.service.UserServiceImpl;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MyTest {

    @Test
    public void test(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        //动态代理代理的是接口
        UserService userservice = (UserService) context.getBean("userservice");

        userservice.add();
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
~搞定收工,运行成功

!扩展

@Test是JUnit测试的基础,他的作用:
1.指定将会抛出的异常类型
2.测试一断代码运行时间。


解决方案二:若是非要使用main函数执行,那就在Maven引入两个插件即可(compiler可以不用引入),——但是有可能会导致中文乱码问题。

maven-compiler-plugin:用来编译Java文件,指定JDK版本等
exec-maven-plugin:用来执行class文件,其中插件配置中需指明执行类的路径。

<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

~运行成功


解决乱码的问题

方法一:
在setting->maven->Runner->VM Options
  一栏中填入 -Dfile.encoding=gb2312
  在这里插入图片描述

方法二:在pom.xml中添入(这个方法我试过,对于我没有解决乱码,可能对你们有用)

<properties>
	<!-- 文件拷贝时的编码 -->
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	<!-- 编译时的编码 -->
    <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

方案二来自:参考博文


~希望可以帮助到您,解决问题

~~~感谢您的光临~~~
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/276444
推荐阅读
相关标签
  

闽ICP备14008679号