Dev/Android

mvn exec:java - 자바 프로젝트 필수 유틸리티 p90

chiftkey 2019. 8. 8. 14:10

mvn exec:java 명령을 실행했을 경우 아래와 같이 오류가 난다.

$ mvn exec:java
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.tuyano:mvn-app >-------------------------
[INFO] Building mvn-app 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ mvn-app ---
[WARNING]
java.lang.ClassNotFoundException: com.tuyano.App
    at java.net.URLClassLoader.findClass (URLClassLoader.java:382)
    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:748)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.796 s
[INFO] Finished at: 2019-08-08T14:06:08+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project mvn-app: An exception occured while executing the Java class. com.tuyano.App -> [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

원인은 mvn exec:java 가 정상동작하기 위해서는 mvn compile이 선행되어야 하는데, 앞 페이지

(p89 2.3.4 프로젝트 클린업) 에서 mvn clean으로 컴파일 결과물을 모두 지워버렸기 때문이다.

따라서 mvn compile을 다시 실행한다음, mvn exec:java 명령을 입력하면 정상동작 함을 알 수 있다.

mvn compile 대신에 mvn package를 사용해도 된다.

$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.tuyano:mvn-app >-------------------------
[INFO] Building mvn-app 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mvn-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\03_Cloud\Dropbox\01_Dev\04_MVN\mvn-app\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mvn-app ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to E:\03_Cloud\Dropbox\01_Dev\04_MVN\mvn-app\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.943 s
[INFO] Finished at: 2019-08-08T14:08:43+09:00
[INFO] ------------------------------------------------------------------------
$ mvn exec:java
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.tuyano:mvn-app >-------------------------
[INFO] Building mvn-app 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ mvn-app ---

***** App class *****

Hi,Taro. Welcome to Maven World!

***** App class *****

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.498 s
[INFO] Finished at: 2019-08-08T14:08:56+09:00
[INFO] ------------------------------------------------------------------------

출처 : https://whiteship.tistory.com/2557