Error: Failed to execute goal org.codehaus.mojo:... Quick solution!

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


The following problem occurs:

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

Solution 1: In this case, I will use the main method to execute the program and use unit test @Test instead.

~It was like this before: running with main

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

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

        userservice.add();
    }
}

~Changed to: use @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();
    }
}
~Finish the job and run successfully

!Extension

@Test is the basis of JUnit testing. Its functions:
1. Specify the exception type that will be thrown
. 2. Test the code running time.


Solution 2: If you must use the main function to execute, just introduce two plug-ins in Maven (the compiler does not need to be introduced) - but it may cause Chinese garbled problems.

maven-compiler-plugin: used to compile Java files, specify JDK version, etc.
exec-maven-plugin: used to execute class files, where the path to the execution class needs to be specified in the plug-in configuration.

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

~Run successfully


Solve the problem of garbled characters

Method 1: Fill in -Dfile.encoding=gb2312
in the setting->maven->Runner->VM Options
  column
  Insert image description here

Method 2: Add it to pom.xml (I have tried this method, but it did not solve the garbled code for me, it may be useful to you)

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

Option 2 comes from: Reference blog post


~Hope it can help you and solve your problem

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

Guess you like

Origin blog.csdn.net/m0_50762431/article/details/117389604