복붙노트

[SPRING] 스프링 부트 및 maven exec 플러그인 문제

SPRING

스프링 부트 및 maven exec 플러그인 문제

나는 pom.xml을 제외하고는 완전히 비어있는 베어 본 Maven 프로젝트를 만들었다.

이 pom을 사용하면 (부모 요소는 주석으로 처리됩니다).

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>springboot-test</groupId>
  <artifactId>springboot-test</artifactId>
  <version>1.0.0-SNAPSHOT</version>

<!--    <parent> -->
<!--        <groupId>org.springframework.boot</groupId> -->
<!--        <artifactId>spring-boot-starter-parent</artifactId> -->
<!--        <version>1.1.9.RELEASE</version> -->
<!--    </parent> -->

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

샘플 실행 :

$ mvn exec:java -Dexec.mainClass=test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building springboot-test 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default-cli) @ springboot-test ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
[WARNING]
java.lang.ClassNotFoundException: test
        at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
        at java.lang.Thread.run(Thread.java:745)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.480 s
[INFO] Finished at: 2014-12-05T13:45:34-05:00
[INFO] Final Memory: 8M/176M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java (default-cli) on project springboot-test: An exception occured while executing the Java class. test -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

이것은 예상됩니다 (이 프로젝트에는 clas 테스트가 없습니다).

이 POM을 사용하여 (즉, 주석 처리를 취소하는 부모 만) :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>springboot-test</groupId>
  <artifactId>springboot-test</artifactId>
  <version>1.0.0-SNAPSHOT</version>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.9.RELEASE</version>
  </parent>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

샘플 실행 :

$ mvn exec:java -Dexec.mainClass=test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building springboot-test 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) > validate @ springboot-test >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) < validate @ springboot-test <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ springboot-test ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.550 s
[INFO] Finished at: 2014-12-05T13:45:27-05:00
[INFO] Final Memory: 12M/178M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project springboot-test: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java are missing or invalid -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

exec-maven-plugin에서도 같은 결과가 발생합니다 : 1.3.2 :

$ mvn org.codehaus.mojo:exec-maven-plugin:1.3.2:java -Dexec.mainClass=test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building springboot-test 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default-cli) @ springboot-test ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.400 s
[INFO] Finished at: 2014-12-05T13:52:46-05:00
[INFO] Final Memory: 6M/157M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java (default-cli) on project springboot-test: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java are missing or invalid -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

추가 정보:

$ java -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
$ mvn -v
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T09:51:42-04:00)
Maven home: C:\dev\bin\apache-maven-3.2.2
Java version: 1.8.0_11, vendor: Oracle Corporation
Java home: C:\progra~1\java\jdk1.8.0_11\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"

질문 :

(부수적으로, 나는 Windows 7이 faimly에 속한다는 사실을 좋아한다 : "dos", 나는 가족을 기다리고있다 : "cp / m"은 Windows 8.1 용으로 구현 됨)

해결법

  1. ==============================

    1.왜냐하면 Spring-Boot는 프로젝트에 추가로 maven 설정을 추가하기 때문입니다. 이클립스를 사용하고 있다면 '효과적인 POM'이라는 탭이 있습니다.

    왜냐하면 Spring-Boot는 프로젝트에 추가로 maven 설정을 추가하기 때문입니다. 이클립스를 사용하고 있다면 '효과적인 POM'이라는 탭이 있습니다.

    이 탭에서 아래에이 스 니펫이 추가 된 것을 볼 수 있습니다.

        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>1.2.1</version>
          <configuration>
            <mainClass>${start-class}</mainClass>
          </configuration>
        </plugin>
    

    따라서 spring-boot를 부모로 실행하면 $ {start-class}의 값을 찾습니다.이 값은 정의하지 않은 한 비어있는 것으로 확인됩니다. 즉 mainClass 매개 변수에 값이 없다는 오류가 표시되는 경우입니다.

    이것을 프로젝트에 추가하십시오 :

    <properties>
        <start-class>com.Test</start-class>
    </properties>
    

    그런 다음 실행하십시오 : clean compile exec : java

    [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ springboot-test ---
    **********test**************
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 2.388 s
    [INFO] Finished at: 2014-12-05T15:25:05-06:00
    [INFO] Final Memory: 17M/231M
    [INFO] ------------------------------------------------------------------------
    

    명령 줄에서 start-class 속성의 값을 제공 할 수도 있습니다.이 값은 pom 파일에서 정의하지 않은 경우에도 작동합니다.

    mvn exec : java -Dstart-class = com.Test

  2. from https://stackoverflow.com/questions/27323104/spring-boot-and-maven-exec-plugin-issue by cc-by-sa and MIT license