Eclipse에서 Maven을 이용해 vert.x 2.0 프로젝트 생성, 디버깅, 빌드하기

개발환경

Eclipse IDE for Java EE Developers Luna packages

JDK 1.8

Vert.x 2.15

이클립스에서 Maven Project 생성

File -> New -> Other -> Maven Project



io.vertx를 선택



io.vertx가 없을 경우 io.vertx archetype 추가


프로젝트 생성



프로젝트를 생성하면, m2e 버그로, pom.xml에 maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e.이라는 오류가 존재한다.

pom.xml에 <pluginManagement>를 추가해 주면 해결된다.

 <build>

    <plugins>

       ...

    </plugins>

 </build>

 <build>

    <pluginManagement>

       <plugins>

             ....

       </plugins>

    </pluginManagement>

 </build>


프로젝트 실행 및 디버깅 설정

Run Configurations -> Java Application -> R Click -> New

Main Tab

Main class : org.vertx.java.platform.impl.cli.Starter


Arguments Tab

Program arguments: run your.package.yourVerticle {-conf conf.json}

-conf 옵션은 conf.json 파일이 없다면, 생략 가능


VM arguments:

쓰레드 풀 사이즈를 조정하고 싶을 때

-Dvertx.pool.worker.size=1

-Dvertx.pool.eventloop.size=1




프로젝트 실행 및 디버깅한 화면

정상적으로 실행되어, 로그가 정상적으로 찍혀 있다.

브레이크 포인트에 걸린 디버깅 화면


프로젝트 빌드


Run As -> Maven install

JDK를 사용하라는 오류 발생

[INFO] Scanning for projects...

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building Project - helloWorld 0.0.1-SNAPSHOT

[INFO] ------------------------------------------------------------------------

[INFO] 

[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ helloWorld ---

[INFO] 

[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helloWorld ---

[INFO] Using 'UTF-8' encoding to copy filtered resources.

[INFO] Copying 6 resources

[INFO] 

[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ helloWorld ---

[INFO] Changes detected - recompiling the module!

[INFO] Compiling 1 source file to G:\project\Test for vert.x\helloWorld\target\classes

[INFO] -------------------------------------------------------------

[ERROR] COMPILATION ERROR : 

[INFO] -------------------------------------------------------------

[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

[INFO] 1 error

[INFO] -------------------------------------------------------------

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 0.911s

[INFO] Finished at: Tue Mar 03 11:25:41 KST 2015

[INFO] Final Memory: 10M/155M

[INFO] ------------------------------------------------------------------------

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project helloWorld: Compilation failure

[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

[ERROR] -> [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/MojoFailureException 


빌드 오류 해결

jre로 설정되어 있던 것을 jdk로 변경해 주면 해결된다.


Window -> Preferences -> Java -> Installed JREs -> Add -> jdk 폴더 추가






Execution Envionments -> JavaSE-1.7 -> jdk 선택


빌드를 다시 시도하여 성공하였다면,

다음과 같은 로그를 볼 수 있으며, target폴더에 jar파일이 생성된다.


[INFO] Scanning for projects...

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building Project - HelloWorld 0.0.1-SNAPSHOT

[INFO] ------------------------------------------------------------------------

[INFO] 

[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ HelloWorld ---

[INFO] 

[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWorld ---

[INFO] Using 'UTF-8' encoding to copy filtered resources.

[INFO] Copying 6 resources

[INFO] 

[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ HelloWorld ---

[INFO] Nothing to compile - all classes are up to date

[INFO] 

[INFO] --- maven-resources-plugin:2.6:copy-resources (copy-mod-to-target) @ HelloWorld ---

[INFO] Using 'UTF-8' encoding to copy filtered resources.

[INFO] Copying 11 resources

[INFO] 

[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloWorld ---

[INFO] Using 'UTF-8' encoding to copy filtered resources.

[INFO] Copying 9 resources

[INFO] 

[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ HelloWorld ---

[INFO] Nothing to compile - all classes are up to date

[INFO] 

[INFO] --- maven-surefire-plugin:2.14:test (default-test) @ HelloWorld ---

[INFO] Surefire report directory: G:\project\Test for vert.x\HelloWorld\target\surefire-reports


-------------------------------------------------------

 T E S T S

-------------------------------------------------------

Running com.sample.HelloWorld.unit.ExampleUnitTest

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.04 sec


Results :


Tests run: 1, Failures: 0, Errors: 0, Skipped: 0


[INFO] 

[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ HelloWorld ---

[INFO] Building jar: G:\project\Test for vert.x\HelloWorld\target\HelloWorld-0.0.1-SNAPSHOT.jar

[INFO] 

[INFO] --- maven-install-plugin:2.4:install (default-install) @ HelloWorld ---

[INFO] Installing G:\project\Test for vert.x\HelloWorld\target\HelloWorld-0.0.1-SNAPSHOT.jar to C:\Users\yakolla\.m2\repository\com\sample\HelloWorld\0.0.1-SNAPSHOT\HelloWorld-0.0.1-SNAPSHOT.jar

[INFO] Installing G:\project\Test for vert.x\HelloWorld\pom.xml to C:\Users\yakolla\.m2\repository\com\sample\HelloWorld\0.0.1-SNAPSHOT\HelloWorld-0.0.1-SNAPSHOT.pom

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 1.724 s

[INFO] Finished at: 2015-03-04T09:58:09+09:00

[INFO] Final Memory: 13M/224M

[INFO] ------------------------------------------------------------------------

 


vertx로 빌드된 jar 파일 실행하기

vertx run your.package.class -cp your.jar)

예)vertx run com.sample.HelloWorld.PingVerticle -cp HelloWorld-0.0.1-SNAPSHOT.jar