报错:Failed to execute goal 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.

解决方案一:这种情况下,我是将用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();
    }
}

~改成了:用@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();
    }
}
~搞定收工,运行成功

!扩展

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

~运行成功


解决乱码的问题

方法一:
在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>

方案二来自:参考博文


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

~~~感谢您的光临~~~

猜你喜欢

转载自blog.csdn.net/m0_50762431/article/details/117389604