Running Verticle in directly in Eclipse (vert.x 2.0)

2,437 views
Skip to first unread message

Angelo

unread,
Jun 19, 2013, 7:07:30 PM6/19/13
to ve...@googlegroups.com
I imported the gradle-template and used the command ./gradlew eclipse and imported the project to eclipse.

Running a single verticle returns the error: "Error: Could not find or load main class".

How can I run a single verticle and/or the entire module in eclipse ?


igerugo sg

unread,
Jun 20, 2013, 1:17:28 AM6/20/13
to ve...@googlegroups.com
Hi, Angelo

I'm using the following task added to gradle/vertx.gradle by me for eclipse .

task runModEclipse(dependsOn: copyMod, description: 'Run the module using all the build dependencies (not using installed vertx') << {
  setSysProps()
  def classpath = [new URL("file:./bin/")] as URL[]
  def pm = PlatformLocator.factory.createPlatformManager()
  def latch = new CountDownLatch(1)
  pm.deployModuleFromClasspath(moduleName, null, 1, classpath, new AsyncResultHandler<String>() {
      public void handle(AsyncResult<String> asyncResult) {
          if (asyncResult.succeeded()) {
              println "CTRL-C to stop server"
          } else {
              println "Failed to deploy module"
              asyncResult.cause().printStackTrace()
              latch.countDown()
          }
      }
  });
  latch.await(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}


modify src/main/resources/mod.json for auto-redeploy:

{
  ....
  "auto-redeploy": true
}

run a module for debug : 

% set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8002,server=y,suspend=n
% gradlew runModEclipse

Cheers,
igerugo
http://ofg.hatenablog.com/


2013年6月20日木曜日 8時07分30秒 UTC+9 Angelo:

Tim Fox

unread,
Jun 20, 2013, 2:39:04 AM6/20/13
to ve...@googlegroups.com
Please explain exactly *how* you're running it, what versions you are
using, etc, etc.

Thanks

On 20/06/13 00:07, Angelo wrote:
> I imported the gradle-template and used the command *./gradlew eclipse* and

Tim Fox

unread,
Jun 20, 2013, 2:44:17 AM6/20/13
to ve...@googlegroups.com
You shouldn't need to do anyone of this (I know this is true for IDEA,
but should be exactly the same for Eclipse).

If you want to debug into a module, just write a test or a main() class
which deploys your module, and you should be able to debug it directly,
with zero special setup.

On 20/06/13 06:17, igerugo sg wrote:
> Hi, Angelo
>
> I'm using the following task added to gradle/vertx.gradle by me for eclipse
> .
>
> task runModEclipse(dependsOn: copyMod, description: 'Run the module using all the build dependencies (not using installed vertx') << {
> setSysProps()
> def classpath = [new URL("file:./bin/")] as URL[]
> def pm = PlatformLocator.factory.createPlatformManager()
> def latch = new CountDownLatch(1)
> pm.deployModuleFromClasspath(moduleName, null, 1, classpath, new AsyncResultHandler<String>() {
> public void handle(AsyncResult<String> asyncResult) {
> if (asyncResult.succeeded()) {
> println "CTRL-C to stop server"
> } else {
> println "Failed to deploy module"
> asyncResult.cause().printStackTrace()
> latch.countDown()
> }
> }
> });
> latch.await(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
> }
>
>
>
> modify src/main/resources/mod.json for auto-redeploy:
>
> {
> ....
> "auto-redeploy": true
> }
>
> run a module for debug :
>
> % set JAVA <http://d.hatena.ne.jp/keyword/JAVA>_OPTS=-Xdebug
> -Xrunjdwp:transport=dt_socket,address=8002,server=y,suspend=n
> % gradlew runModEclipse
>
> Cheers,
> igerugo
> http://ofg.hatenablog.com/
>
>
> 2013年6月20日木曜日 8時07分30秒 UTC+9 Angelo:
>> I imported the gradle-template and used the command *./gradlew eclipse*and imported the project to eclipse.

igerugo sg

unread,
Jun 20, 2013, 9:35:08 AM6/20/13
to ve...@googlegroups.com
Hi, Tim

I'd like to use "auto-redeploy" with Eclipse and the gladlew command.
I don't know how to give the gladlew command the classpath of the "bin" folder generated by eclipse, do as "vertx runmod -c " command. 
What is the best method?

There is a problem with the runModEclipse task  that I implemented.
Specifically, PathAdjuster.adjust(vertx, filename) returns an incorrect path,
, because ((VertxInternal)vertx).getContext().getPathAdjustment()  is null in Verticle#start().

To return a correct path in Verticle#start(), write:
    if(((VertxInternal)vertx).getContext().getPathAdjustment() == null)
    ((VertxInternal)vertx).getContext().setPathAdjustment(Paths.get("bin"));

Of course, this is not pleased. :)

Many thanks for your help,
igerugo

2013年6月20日木曜日 15時44分17秒 UTC+9 Tim Fox:

Tim Fox

unread,
Jun 20, 2013, 10:01:04 AM6/20/13
to ve...@googlegroups.com
Now, I'm confused - I thought you wanted to debug your module?

Angelo

unread,
Jun 20, 2013, 10:08:10 AM6/20/13
to ve...@googlegroups.com
I expected that the "auto-redeploy" option would work like nodemon (https://github.com/remy/nodemon) such that we develop verticles and in case of changes in the module directory the module would be reloaded automatically.

Tim Fox

unread,
Jun 20, 2013, 10:09:06 AM6/20/13
to ve...@googlegroups.com
It does

igerugo sg

unread,
Jun 20, 2013, 10:25:45 AM6/20/13
to ve...@googlegroups.com
Hi, Tim

> I thought you wanted to debug your module? 

No,  I did't.
I want to know how to give the gladlew command the classpath of the "bin" folder generated by eclipse, do as "vertx runmod -c " command. 

Sorry, I am poor English,
igerugo

2013年6月20日木曜日 23時01分04秒 UTC+9 Tim Fox:

Tim Fox

unread,
Jun 20, 2013, 10:31:59 AM6/20/13
to ve...@googlegroups.com
On 20/06/13 15:25, igerugo sg wrote:
> Hi, Tim
>
>> I thought you wanted to debug your module?
> No, I did't.

Err, ok... The first half of this thread definitely seemed to be about
debugging a module, I quote:

"run a module for debug : "

So I guess we have move onto a new subject now, best to start a new
thread in this case, but anyway...

./gradlew runMod doesn't support passing parameters such as -cp
currently, although it could easily be extended to do this.

Instead you can use

vertx runmod -cp <classpath>

There is a document in the vert.x 2.0 docs on the website which
describes how to do this.

Angelo

unread,
Jun 20, 2013, 11:59:30 AM6/20/13
to ve...@googlegroups.com
Maybe this task could simplify the development :)

task runModEclipse(dependsOn: copyMod, description: 'Run the module using all the build dependencies (not using installed vertx') << {
  setSysProps()
  def classpath = [ new URL('file:src/main/resources/'), new URL('file:src/test/resources/'), new URL('file:./bin/')] as URL[]

Tim Fox

unread,
Jun 20, 2013, 12:54:05 PM6/20/13
to ve...@googlegroups.com
This thread seems to be talking about 14 different things....

igerugo sg

unread,
Jun 20, 2013, 9:36:55 PM6/20/13
to ve...@googlegroups.com
Hi, Tim

> ./gradlew runMod doesn't support passing parameters such as -cp 
currently, (snip)

Ok, I'm looking forward to it supporting. :)

Thanks,
igerugo

2013年6月20日木曜日 23時31分59秒 UTC+9 Tim Fox:

Tim Fox

unread,
Jun 21, 2013, 3:07:44 AM6/21/13
to ve...@googlegroups.com
On 21/06/13 02:36, igerugo sg wrote:
> Hi, Tim
>
>> ./gradlew runMod doesn't support passing parameters such as -cp
> currently, (snip)
>
> Ok, I'm looking forward to it supporting. :)

Are you submitting a PR? :)

Tim Fox

unread,
Jun 21, 2013, 9:17:53 AM6/21/13
to ve...@googlegroups.com
I've added runModEclipse and runModIDEA targets in vertx-gradle-template :)

On 20/06/13 16:59, Angelo wrote:

igerugo sg

unread,
Jun 21, 2013, 10:12:15 AM6/21/13
to ve...@googlegroups.com
Hi, Tim
Oh, thank you!!  :-)

2013年6月21日金曜日 22時17分53秒 UTC+9 Tim Fox:

Per Weinberger

unread,
Aug 15, 2013, 4:08:26 PM8/15/13
to ve...@googlegroups.com
Hi,

Could you please explain to me, like I'm five years old, how to do this. I'm getting a NPE (the vertx variable is null) when I do this. I would like to run the PingVerticle which gets autogenerated by the mvn setup in Eclipse.

Thanks,
Per Weinberger

Tim Fox

unread,
Aug 15, 2013, 4:19:20 PM8/15/13
to ve...@googlegroups.com
Take a look at ModuleIntegrationTest in the standard build, that already
deploys your module.

Tim Fox

unread,
Aug 15, 2013, 4:23:50 PM8/15/13
to ve...@googlegroups.com
On 15/08/13 21:19, Tim Fox wrote:
> Take a look at ModuleIntegrationTest in the standard build, that already
> deploys your module.

Alternatively just call mvn vertx:runModEclipse from the command line,
or from inside Eclipse. No special setup is needed for that either.

Per Weinberger

unread,
Aug 16, 2013, 4:16:18 AM8/16/13
to ve...@googlegroups.com
Thanks, now I get it. One question though. How does the System.getProperty("vertx.modulename"in the start method work? Where does (how) the property "vertx.modulename" get set? 

Thanks again,
Per 

Tim Fox

unread,
Aug 16, 2013, 4:20:45 AM8/16/13
to ve...@googlegroups.com
On 16/08/13 09:16, Per Weinberger wrote:
Thanks, now I get it. One question though. How does the System.getProperty(
"vertx.modulename") in the start method work? Where does (how) the property 
"vertx.modulename" get set? 

It gets set in the custom JUnit test runner that we use to run the tests:

https://github.com/vert-x/testtools/blob/master/src/main/java/org/vertx/testtools/JavaClassRunner.java#L120

I briefly mentioned this in my last post, but an even easier way to run your module in the IDE might just to be execute the maven task:

mvn vertx:runModEclipse

I'm not an Eclipse IDE user but I believe it's possible to run Maven targets directly from a menu in Eclipse (?)

Per Weinberger

unread,
Aug 16, 2013, 5:21:35 AM8/16/13
to ve...@googlegroups.com
You're right. In Eclipse, project context menu -> Convert to Maven project. Then Debug As -> Maven Build... Set the goal to "vertx:runModEclipse" and watch the magic happen.

(I couldn't directly convert the project to a maven project but this article explained how to fix that: http://stackoverflow.com/questions/15065093/an-internal-error-occurred-during-updating-maven-project-unsupported-iclassp)

Of course, you also need to install the m2e plugin.

Thanks for your help!
Per
Reply all
Reply to author
Forward
0 new messages