Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to debug a standalone app built with Maven from within eclipse

 
Christopher Burns
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone shed some light on this?

I have found a couple of web pages that describe it, but none of them seem to work.

I can launch Maven in debug mode, get it waiting on a port, then launch the app from within eclipse, connecting to that port, but I get an error saying that the project requires a POM.xml, which it has.

TIA for any input.

Cheers,

Chris
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a little unclear on the details.

When you say "I can launch Maven in debug mode, get it waiting on a port," do you mean that you added the -Xdebug (and related) JVM command line options to the java command that runs Maven? Or did you download the Mavne source code creating and Eclipse project from it and starting that in debug mode in Eclipse? Or do you mean something else? (If either of the last two, what "port" do you mean?)

When you say "then launch the app from within eclipse, connecting to that port," what app are you talking about? And how does that app go about connection to the port? Or are you thinking that Eclipse should connect to the debug port for Maven (if you started Maven using -Xdebug)?

Regarding the missing pom, when you launched Maven did you do that in a directory that contains a pom.xml?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're trying to debug the *app*, and not Maven, can't you just launch the program via the run/debug command?
 
Christopher Burns
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Well, if I actually gave you helpful information it wouldn't make this much of a challenge, now would it? :P Sorry about that... end of the week, and brain not firmly seated in socket.

Here's the scoop. I have a non-web, standalone Java app that I want to run/debug. It has a class that defines . The project is being built with Maven, and that works just fine.

What I am trying to do is launch and debug this app using Maven goals. I am not trying to debug Maven itself. Currently I am building using the clean and package goals.

I saw a couple of pages that recommended creating a Java project with no code in it, then creating a debug config that referenced my Maven project in the Source Lookup Path. When I try to debug into that, I get the "no pom.xml can be found" error. These instructions, which I cannot find now, said something about launching Maven from the command line using the mvn-debug batch file (it actually showed how to alter the mvn.bat to make it debug, but I already had it in my distribution and it had the same values as were recommended in the article), which got Maven waiting for a connection on port 8080, by default. Then I went into eclipse and tried to attach to that port, but it never hooked up.

Have also tried the instructions at: to no avail.

If anyone has done this and can guide me through it, I would be much obliged. I cannot imagine this is a difficult or uncommon scenario, but I am missing something.

Thanks,

Chris
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if this plugin will do what you need: http://mojo.codehaus.org/exec-maven-plugin/usage.html
 
Christopher Burns
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,

Using this, how would I launch a debug session?

Thanks,

Chris
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17995
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, it's monday morning, and my brain's more or less in socket, but I'm not sure about the eyeballs, so forgive me if I misread anything.

If you have a Maven project, you should be able to "eclipse-ify" it using the mvn goal eclipse:eclipse. There's also an IntelliJ Idea goal, BTW. What this does is take the POM and use it to generate the eclipse .project and .classpath files.

There's a Maven plug-in for Eclipse (m2eclipse) although it and I are having heated words at the moment. Apparently there's something missing from the install for Eclipse 3.4 and no definitive work-around or solution. You don't actually need the plugin, but it is kind of handly.

To debug a standalone app built with Maven, the easiest way is to use the Eclipse debugger to build a debug profile that runs against the Maven target. For a standalone JAR, that generally means put "target/myjar-version.jar" or something like that in the classpath for the debug session, indicate the main class, and debug in the usual way. Add any additional external JARs you need to the debug's profile's CLASSPATH tab.
 
Christopher Burns
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Thanks for that... will give that a go right now.

Totally forgot to mention, as I now see, that I am indeed using m2eclipse. I was hoping that this would be facilitated with that, but apparently no.

What problems are you having with it?

Cheers,

Chris
 
Christopher Burns
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Alright... this is weird. I had already done this and I kept getting a "cannot find class with main()" error. Today it works.

Just to be sure I understand this, essentially I am building the project with Maven, and then, totally independent of Maven, am debugging the resultant Java app. Is that correct?

Is there no way to integrate the two, such that when I build with Maven, successful completion launches into the debugger?

Thanks!

C
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17995
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christopher Burns wrote:Hi Tim,

Alright... this is weird. I had already done this and I kept getting a "cannot find class with main()" error. Today it works.

Just to be sure I understand this, essentially I am building the project with Maven, and then, totally independent of Maven, am debugging the resultant Java app. Is that correct?

Is there no way to integrate the two, such that when I build with Maven, successful completion launches into the debugger?

Thanks!

C


In answer to your question about m2eclipse, I can't install it because a pre-requisite is missing. I think it's the part that will display the graphical view of dependencies. It's a known problem, so I hope they'll fix it soon. "Soon", alas isn't always soon enough. People have been nagging the dozer development team to release the Maven repository version of their project for something like 4 months, now and so far no satisfaction. Codehaus seems to have lost direction over the last year or 2.

You are correct. Maven and Eclipse co-operate, but they're not tightly interconnected. Maven is designed not to be dependent on an IDE, and I find that good, since not every computer I do builds on even has a GUI, much less a copy of Eclipse.

So I don't know of anything that would launch the Eclipse debugger. In theory, you could develop a custom mojo for that, however.
 
Christopher Burns
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

First off, thanks for all of the help and explanation. It really illuminated things for me, and made me comfortable that I do understand what is going on, I was just looking for a piece of the puzzle that doesn't exist.

As for your woes, I am running Ganymede (latest update) and installed m2eclipse from the update site with no problems at all. I have the dependency graph tab and it is working just fine. Is this a sporadic problem or did I just get lucky?

Cheers,

C
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17995
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe they finally fixed it. I'll have to check!
 
Rongsberg Wood
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just curious about this, did you resolve the problem? If not, check this out: http://it-worx.blogspot.com/2010/03/debug-maven-project-in-eclipse.html
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to Javaranch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic