Author Topic: Issue with debugging Java Maven Project in beta6  (Read 373 times)

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Issue with debugging Java Maven Project in beta6
« on: October 12, 2018, 10:33:48 pm »
I imported my pom.xml and took all the default project settings.

Project Properties for debug is set to this:
Code: [Select]
java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 %cp .
When I try to debug, SE tries to launch:

Code: [Select]
java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -classpath /home/nas/classes/:/home/nas/myproj/ myproj.MyProj
Then I get error:

Quote
Error: Could not find or load main class myproj.MyProj

I think that the issue is the directory passed to "-classpath". My .class files are in directory "/home/nas/myproj/target/classes".

The "target" part is added by maven.

So I think that %cp is not expanding properly? Or I need to configure something else?

I'm on beta6, Linux x64, CentOs 7.2

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Issue with debugging Java Maven Project in beta6
« Reply #1 on: October 12, 2018, 10:35:11 pm »
Same issue when I try to execute. When I manually add the "target" directory when trying to execute, I am able to execute. So there is an issue with the expansion of %cp missing the "target" directory in Maven projects.
« Last Edit: October 12, 2018, 10:37:02 pm by rowbearto »

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Issue with debugging Java Maven Project in beta6
« Reply #2 on: October 13, 2018, 04:11:12 pm »
Look for mavenhello-classpath.tar.gz on support that allows you to recreate this issue.

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Issue with debugging Java Maven Project in beta6
« Reply #3 on: October 13, 2018, 04:18:10 pm »
As a workaround, in Project Properties for "Execute" and "Debug" I used "-classpath %rptarget/classes/"

This worked for execute, and works for debug as well if I don't set a breakpoint.

But when I set a breakpoint on the printout of "Hello World" in MavenHelloWorld.java, then when I do a debug it does not stop at the breakpoint, but keeps going. Perhaps I should start another thread for this not stopping at breakpoint issue?

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 960
  • Hero Points: 72
Re: Issue with debugging Java Maven Project in beta6
« Reply #4 on: October 15, 2018, 01:22:25 pm »
We'll take a look at the import for maven.  I'll check the breakpoint while I'm looking at it.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 960
  • Hero Points: 72
Re: Issue with debugging Java Maven Project in beta6
« Reply #5 on: October 15, 2018, 02:39:32 pm »
Updated the maven template for RC2. 

I couldn't get a breakpoint to catch for that file either.  I'm looking in to it.

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Issue with debugging Java Maven Project in beta6
« Reply #6 on: October 15, 2018, 02:48:43 pm »
Working with this project more, I discovered a few more issues with SlickEdit and Maven.

1) The template's "Execute" works fine for a very simple Maven project that does not use any imported libraries (libraries that are specified in pom.xml file). But as soon as I use an imported library, the template's classpath does not find the .class files for that library and I can't execute it.  These .class files are embedded in .jar files that maven downloads. For execution for projects like this, I found I had to change the project properties Execute line to something like this:

mvn -q exec:java -Dexec.mainClass=myproj.MyClass -Dexec.args="arg1 arg2 arg3"

2) As the execute line didn't work for using an imported library, I doubt the template's debug line would work either because it also would not find the .class files. And for debug looks like java needs to be executed with many special parameters in a debug mode. How to accomplish this for a maven project that uses an imported library?

3) Perhaps I should start another thread for this point, but how to perform tagging on the source code for imported libraries? Searching the forum I found feature requests for this, not sure if it was ever implemented. And while on the subject, how to tag the general Java libraries so I can have autocomplete for those?

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 960
  • Hero Points: 72
Re: Issue with debugging Java Maven Project in beta6
« Reply #7 on: October 15, 2018, 08:14:55 pm »
1 & 2) The template tries to be generic, but won't work for everything.  For now, all you can do is customize the targets by hand.

3) There's no support for auto-tagging the dependencies for maven. 

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 960
  • Hero Points: 72
Re: Issue with debugging Java Maven Project in beta6
« Reply #8 on: October 16, 2018, 01:45:36 pm »
The problem with not stopping at the breakpoint is fixed for RC2.

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Issue with debugging Java Maven Project in beta6
« Reply #9 on: October 16, 2018, 01:52:07 pm »
Thanks!

Any hints on how to debug a maven project with dependencies? Do I need to add the directories of the maven dependencies to the classpath on the command line? Can I point to directories with jars in classpath? Does it have to be the directory that immediately contains the jars, or can I give the .m2 directory tree and java will go to the subdirectories to look for the class?

Or can a "mvn" command be used and we can tell it all the debug parameters to pass to "java" executable?

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Issue with debugging Java Maven Project in beta6
« Reply #10 on: October 16, 2018, 02:10:39 pm »
re: debugging, found a link that gives some clues:

https://stackoverflow.com/questions/2935375/debugging-in-maven

Specifically need to run "mvnDebug" and possibly set an environment variable with the parameters?

Will need to try it when I have time.

Could be nice to have this in the maven template so that it will "just work", one can dream :)

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 960
  • Hero Points: 72
Re: Issue with debugging Java Maven Project in beta6
« Reply #11 on: October 16, 2018, 02:37:09 pm »
Use the environment variable approach.  The other answers with putting the debug args in the -Dexec.args="" seems to just pass the arguments to the program you're executing.  Perhaps that may work if it's configured to launch a new JVM for the exec.

For your sample project, I changed the Debug tool command line to "mvn exec:java -Dexec.mainClass=mavenhelloworld.MavenHelloWorld" and clicked on advanced and added the MAVEN_OPTS environment variable as "-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000".

When you hit F5 to start the debugger, the program will start suspended, but SlickEdit will not automatically go into debug mode because it doesn't recognize this maven command as invoking the debugger.  So you'll need to go to Debug -> Attach Debugger -> Attach to Java virtual machine...  Port number 8000, and select your workspace as the Session name, so your workspace breakpoints will be used.  Hit OK.

The target is still suspended at this point, so hit F5 again to start it up. 

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Issue with debugging Java Maven Project in beta6
« Reply #12 on: October 16, 2018, 02:43:27 pm »
Thanks for checking that out Patrick!

Seems like lots of extra clicks especially to do the attach. When I debug in eclipse its pretty smooth, but would rather not use eclipse. Would be nice if a future version of SlickEdit would make this seamless.

Also, I think "mvnDebug" already has many of those options for "java" set, but there is also a "MVN_DEBUG_OPTS" environment variable. I don't have time to look into it at the moment, but if you have a few more minutes please check out "mvnDebug".

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 960
  • Hero Points: 72
Re: Issue with debugging Java Maven Project in beta6
« Reply #13 on: October 16, 2018, 03:01:23 pm »
Right, that does the same thing.  For some reason  I thought my OS package didn't have that script, but it does.  You just have to set the same command line as before, but with mvnDebug instead of mvn.  I added a check in RC2 so 'mvnDebug' is recognized as starting a JDWP debug session, so the debugger should just start up when you hit F5, without the attach steps.

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Issue with debugging Java Maven Project in beta6
« Reply #14 on: October 16, 2018, 03:07:16 pm »
Thanks Patrick! You da man!