SlickEdit Community

Archived Beta Discussions => SlickEdit 201x Beta Discussions => SlickEdit 2018 v23 Beta Discussion => Topic started by: rowbearto on October 12, 2018, 10:33:48 PM

Title: Issue with debugging Java Maven Project in beta6
Post by: rowbearto 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
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto 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.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto on October 13, 2018, 04:11:12 PM
Look for mavenhello-classpath.tar.gz on support that allows you to recreate this issue.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto 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?
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick 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.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick 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.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto 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?
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick 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. 
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick on October 16, 2018, 01:45:36 PM
The problem with not stopping at the breakpoint is fixed for RC2.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto 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?
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto 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 :)
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick 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. 
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto 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".
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick 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.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto on October 16, 2018, 03:07:16 PM
Thanks Patrick! You da man!
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto on October 16, 2018, 05:31:45 PM
If I create a new SlickEdit project and make it a Java Project instead of Maven Project, would I be able to use "mvnDebug" in the debug command and be able to debug my java program?

I'm thinking of moving away from SE Maven Project so I can get the live errors, which should increase productivity.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick on October 16, 2018, 06:18:54 PM
I don't think that will work.  The problem is the java project template doesn't let you edit the command line, but builds up command lines from the information from java dialogs.  You can't really enter the maven commands in the java dialogs, and if you try to make an end run around the dialogs and edit the vpj file, the code that reads the configuration from the project file seems to get confused. 

I haven't fully checked this out, as I have found a bug with live error's jdk detection for openjdk 1.8 on linux that I need to work through.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto on October 16, 2018, 06:34:23 PM
What if I added a new tool in the Project->Properties->Tools tab? Then I'd be able to run my own command with that, right? So I could do my maven build/exec from a new tool so I could get the live errors and build/exec with one project. Then I'd just be missing the debug.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick on October 16, 2018, 06:54:23 PM
Creating your own build and execute targets would work.  No debugging without creating your own debug tool, and then attaching.  Getting the bindings for build and execute to call your tools would be a hassle, since the commands that handle those expect to call the well known 'execute' and 'build' targets. 
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto on October 17, 2018, 02:35:32 AM
I started to make a Java Project so I can see Live Errors. I think I ran into what you (Patrick) mentioned before:

Quote
I have found a bug with live error's jdk detection for openjdk 1.8 on linux that I need to work through.

In "JDK installation directory", I put the "bin" directory of my 1.8 JDK and also tried the parent dir of bin, and I get error: "Path to JDK 1.6 or later must be specified in order to use Live Errors". Is this the same problem you are tracking down?

I'm on RC1, Linux x64, CentOS 7.2
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick on October 17, 2018, 03:33:59 PM
Yes.  That's fixed for RC2.  It's finding the directory and compiler library correctly, but isn't extracting the version number from javac correctly.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto on October 17, 2018, 05:10:43 PM
Excellent! I'm thinking of switching to Java 11 in next few months, did you also test with Java 11 (and also 9 and 10)?
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: Marcel on October 18, 2018, 01:24:00 PM
If you are thinking about modularized applications, I doubt SE is ready for that.  It might work for unnamed module mode, I was able to compile but don't know yet if I can debug/run (too busy getting rid of old sun crypto apis).
My work place is using Gradle instead of Maven, but the problems are the same.  In the past I have made suggestions for SE to index the Gradle cache but have changed my mind about that. My cache has over 1000 jars with frequent updates, so indexing that is clearly not workable. I want SE to remain usable as an editor, not keep itself busy indexing 3rd-party libraries which I may never need to dive in. Maybe there is a smarter way to do late/as needed fine-grained indexing, for example when pulling up a 3rd-part class file.

For the heavy Java lifting, I am using Intellij.  It is friendly enough to download the matching sources jars for everything it needs from the Gradle cache.  The price to pay for this is a few minutes of loading time when opening a project. It doesn't do full indexing of the Gradle cache, I think all they do is build a package/class index.  it is enough to debug 3rd-party libraries at the source level and resolve imports.  If you need to clean up import lists, locate unused code, or need refactoring, IntelliJ is your friend.

SE can do certain things very well, but I don't expect it do be a replacement for a full-fledged specialized IDE. It cannot possibly replace VisualStudio or IntelliJ, they have two orders of magnitude more staff to support their products.

Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick on October 18, 2018, 01:58:48 PM
It works with openjdk 11, and 10, I didn't check 9. 

@Marcel - agree that some incremental way of dealing with the huge number of jars would be needed.  Or a way for SlickEdit to ask on a tag not found if we should try to find the corresponding source jar on a background thread. 

The ability to pull down source jars was only recently added for our Gradle support, so right now it's only used to pull down the Kotlin and Scala standard library source.  That may expand a little for the point release.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto on October 18, 2018, 02:03:57 PM
For indexing the dependencies, for Maven the pom.xml says exactly which dependencies my application is using, so limiting indexing to just those jars would do the trick?

In my case I'm writing simple tools in Java, not some big application.

In the case of debugging a maven project when using it as a Java project in SE, I think I know a workaround where I would not need to perform an attach and could debug directly. In the Build->Java Options->JRE it allows to specify "JRE app name". Instead of "java", I could put my script there "myjava", and then "myjava" would repackage the command line options and run mvnDebug instead. Would that work?
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: patrick on October 18, 2018, 02:33:07 PM
Yes. Support for extracting that and locating/locating the source jar files will have to go in the v23 point release.

A script works.  The only gotcha I see is that the parameters passed to the script get a "." where the qualified main class name would normally be.
Title: Re: Issue with debugging Java Maven Project in beta6
Post by: rowbearto on October 18, 2018, 02:54:50 PM
But even with locating the source dependencies in a Maven project, I'd still not be able to get the "Live Errors", which sounds like much work and could not be put into a point release? Live Errors in Maven probably needs to go into a future release?

So I'll probably end up using Java Project in the short term (until Live Errors in Maven is ever supported), manually setting up tag files for my Maven dependencies, and using my script hack to do debugging if I wanted to debug in SE (I'm using eclipse now for debugging, but would be nice to stay in SE). But in the real short term when I don't have time to hack up the Java Project I'll stick with the Maven project, not index the dependencies, not have Live Errors and use eclipse for debugging until I have time to work the other things out.