wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes How to debug a standalone app built with Maven from within eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to debug a standalone app built with Maven from within eclipse" Watch "How to debug a standalone app built with Maven from within eclipse" New topic
Author

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

Christopher Burns
Ranch Hand

Joined: Oct 21, 2008
Posts: 33
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


"It is our choices, much more than our abilities, that make us who we are."
- Albus Dumbledore
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5811
    
    7

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?


JBoss In Action
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 21, 2008
Posts: 33
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

Joined: May 14, 2008
Posts: 5811
    
    7

See if this plugin will do what you need: http://mojo.codehaus.org/exec-maven-plugin/usage.html
Christopher Burns
Ranch Hand

Joined: Oct 21, 2008
Posts: 33
Hi Peter,

Using this, how would I launch a debug session?

Thanks,

Chris
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Christopher Burns
Ranch Hand

Joined: Oct 21, 2008
Posts: 33
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

Joined: Oct 21, 2008
Posts: 33
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

Joined: Jun 25, 2001
Posts: 15950
    
  19

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

Joined: Oct 21, 2008
Posts: 33
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

Joined: Jun 25, 2001
Posts: 15950
    
  19

Maybe they finally fixed it. I'll have to check!
Rongsberg Wood
Greenhorn

Joined: Mar 11, 2010
Posts: 1
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

And welcome to Javaranch!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to debug a standalone app built with Maven from within eclipse
 
Similar Threads
Cool Eclipse feature of the day
EJB3 Debug with Eclipse and JBoss ( Remote interface )
debug j2ee application from Eclipse
IntelliJ Maven Project Startup Error
Debugging a web appplication from Eclipse