Why is IntelliJ skipping breakpoints while remotely debugging - debugging

I have been asked to debug a Java application installed in Apache Karaf (OSGi) running in a VM hosted on my dev machine. My colleague has been able to do remote debugging successfully using Eclipse. My tool of choice is IntelliJ and in my attempts to debug remotely, IntelliJ connects successfully (via socket). If I pause the debugging session, the Karaf console freezes as expected and resumes when I click continue. But when I am paused I can see the following message in IntelliJ and my breakpoints are ignored.
Target VM is not paused by breakpoint request. Evaluation of methods is not possible in this mode.
What does this mean? I have searched and also gone through the documentation for IntelliJ. Why can Eclipse allow working breakpoints and IntelliJ doesn't?

Firstly, one presumes that you have started up your OSGI container (for example, Fuse Fabric) in debug mode. Often this is done by adding the argument debug to the start script.
For example:
c:\> startfabric.bat debug
As Tim noted, you just now need to make sure that your source code is exactly synced with whatever is deployed to the OSGI container.
To be sure, check out the exact same source code version as what is deployed to the server, and choose Build -> Rebuild Project. If necessary, do a mvn clean install on your machine, and deploy a bundle / feature that you have built yourself - then you know that the code you have locally should exactly match what is deployed.
Lastly, check your debug panels in IntelliJ, and remove any Watch expressions that might be interfering whilst in debug mode.

Related

Debugging of a JVM application (Java or Scala) with breakpoints in Gradle and IntelliJ 2016.3.5

I have a JVM application that I need to debug using breakpoints with a Gradle task (run and test as dependencies) within IntelliJ 2016.3.5.
There are various sources on how to accomplish debugging with Gradle and IntelliJ:
Debug Gradle plugins with IntelliJ
Using Intellij to set breakpoints in gradle project (most helpful one)
https://youtrack.jetbrains.com/issue/IDEA-119551
https://youtrack.jetbrains.com/issue/IDEA-86465
https://youtrack.jetbrains.com/issue/IDEA-119494
However, these sources are either outdated or meant for another scenario. I do not want to debug the Gradle script but the JVM that runs the actual Java/Scala application. Moreover, the recent versions of IntelliJ use the Gradle Tooling API, which does not offer the option to turn off the daemon. A native support from JetBrains is only provided using the debugging button on the run and test tasks directly, but not if they are defined as dependencies from another task (e.g., check).
According to the sources, this is the way to go then:
run { // or test, doesn't matter
jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
// xor, or both, doesn't seem to make any difference
debug true
}
In any way, Gradle (or the JVM) will then start to listen on port 5005:
Then, I have created a remote configuration with the following parameters:
But when I start the IntelliJ remote debugging task, it fails:
I have also tried using port 5006 and suspend=n without success. Before that, I tried using Gradle arguments in the IntelliJ-Gradle run task. Then, it indeed connected, but seemingly to the Gradle script and not the application JVM because it did not interrupt at the breakpoints. How to fix this?
Debugging of gradle tasks like 'test', 'run', actually all gradle tasks that implements JavaForkOptions interface, should work in IntelliJ since 2014 year
Meanwhile, I found the solution myself. If you have a similar issue, follow the approach mentioned above using the debug option.
test {
debug true
}
But make sure that external connections are accepted in the settings after IntelliJ restarted:
Then, it connects to the correct JVM and interrupts at the breakpoints using the remote task:
If you restart IntelliJ, however, with the very same option (external connections) enabled, then the debugging task might fail due to a blocked port:
So, for some reason, IntelliJ blocks that port after a restart but it is necessary to enable the setting for the debugging task to work. That's odd and I don't think it is intended to behave like that.
Anyways, if you disable the setting and restart, the port will be open again. Then, re-enable the setting, do not restart, just run the Gradle task, and the debugging task. It will work.
I hope this helps anyone else looking for an intermediate solution to debug JVM applications with Gradle and IntelliJ among the confusing and partially outdated answers out there. If anyone has a better or simpler suggestion, feel free to append your answer.

Debugger doesn't stop at break points (Arquillian, TomEE, OpenJPA Enhancer, Maven, JUnit, and IntelliJ)

I'm writing a web app that uses JAX-RS (Apache CXF) and JPA (Apache OpenJPA) and is deployed using TomEE+. I've started using Arquillian via the arquillian-tomee-embedded maven dependency to unit test my REST services.
When I use IntelliJ to launch the test phase of Maven's build lifecycle everything works great. It runs OpenJPA's enhancer on my JPA Entities, kicks off the unit tests, and I'm able to successfully call my web services and they're able to successfully access the database.
Unfortunately, if I launch the test phase in debug mode everything still works but none of my breakpoints hit. What must I do to correct this problem?
I've found a tedious workaround. I can right click each unit test and run in debug mode and the debugger will hit breakpoints...but I have to manually run the OpenJPA enhancer beforehand in order for the JPA code to work.
When you "launch the test phase in debug mode ", it means that Maven runs in debug mode, not that it debugs your app. You cannot debug your app through maven. Maven runs the tests using surefire-plugin, and you cannot use breakpoints and debug.
There can be two possibilities:
1) The code / break-point(s) are not reachable / not getting called with current context.
2) You are NOT running application in Debug mode.
Make sure that you are Debugging the application and not run it like "Run As..."
Considering that you are using Eclipse, Run -> Debug As -> <-Your Target Application->
Also make sure that where ever you have added breakpoints, those lines are reachable.
I've hit problems with IntelliJ debugging not hitting breakpoints before. You may have luck disabling the JUnit plugin and restarting IDEA.

Intellij debug configuration with only an external tool

I am coding bukkit plugins on my Mac laptop, and to test I want to launch a jar file within the Intellij debug system (current version). If you dont know what bukkit is, all that really matters is that I am trying to execute
"java -jar craftbukkit.jar" in a certain directory.
I have figured out how to do this using a Maven configuration. Basically I created a new Maven configuration, then just ignored everything about Maven and added an external tool to the "Before Launch" section. Everything works, but there is this somewhat annoying notification whenever I close the server session. (Bukkit is the name of the configuration).
Error running Bukkit: No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.
Basically I am wondering if
I could somehow prevent this warning from showing up as a bubble/in the event log
I could configure the Maven settings somehow such that it wouldnt do anything Maven related.
I could use another configuration method to just use the external tool I wish.
Also, for the record, I have tried setting the home directory and setting the maven directory, but while it does fix the errors, it causes the logger to try to run a maven session which quits out with another error. Basically if I try to fix the pop up the obvious way, it only leads to another error since I am not actually trying to use Maven.
Finally, you may say "its just a little balloon, who cares". True, its not a huge inconvenience, but to me it is worth at least doing some research before giving up on.

what is debug mode and how do i turn it on using jboss in windows command console?

I would like to know what is debug mode in jboss. I've used django before and when I turned on debug mode, any change I make while the localhost is running will be detected and refreshing the page will show the changes. Is that the same in jboss debug?
I use maven to install the project then start jboss in windows command console. How do I turn on debug mode for jboss 5.1.1?
Maven clean install takes about 8 minutes, then restarting the server is another 5-7 minutes. I am wasting a lot of time for many small changes.
You can enable remote debugging on the JVM allowing you to connect via your IDE and you can from there run your app in bebug (stop the execution and go step by step). Look on the statup script, the remote debug option has been put in comment. Debug allow you to update some class (you need to connect the IDE to it and update your class via the IDE, the JVM and JBOSS won't detect the change them self). But if you update any container managed part (EJB, persistance context, servlet) you will need to redeploy the application. So I don't think it will give you what you need.
Why do you do a clean install each time? A simple install should create your package and prevent any compilation, file copy if the source is older than the build artifact. You can also redeploy your application without shutting down JBoss. There is Maven goal for that. By default I think, if JBoss detect that the application file (ear or war) has been change (the timestamp is lower than deploy time) it will redeploy the application (some time redeploy is unfortunately not enough, most of the time class loader issue. Never get issue with JBoss as 7 but class loading has been redone).
If you can upgrade to JBoss AS 7, it is far quicker and Java EE 6 make your application lighter impacting positively the build time. But this may require to much refactoring.

IntelliJ forcing me to restart my app on every code change

I am on Grails 1.3.5 and IntelliJ 9.0.4 on a Mac with the latest JDK
I have the simplest of Grails projects: a helloworld that simply renders a string directly from a controller. I created it through the New Project wizard in IntelliJ. That went fine and IntelliJ picks up the correct grails SDK.
The problem is that IntelliJ makes me restart the app to see any changes I make to my code, (e.g. changing the "hello world" string.
If I edit the same controller with a text editor (eg TextMate) and run the app from the command line with grails run-app I do get hot code replacement, which is obviously what I want...
Anyone got a clue?
Some points:
I strongly recommend using the latest IntelliJ X EAP (http://confluence.jetbrains.net/display/IDEADEV/IDEA+X+EAP) since Grails support has been improved a lot since 9.0.x
If your IntelliJ config files got messed up, you can easily recreate them with 'grails integrate-with --intellij'. N.B. this recreates the config files in and old format and IntelliJ suggest to upgrade them - follow this procedure
Make sure your run configuration has uses at least the same memory settings than Grails uses when run from the command line, I'm fine with setting the 'VM parameters' field to '-XX:MaxPermSize=256m -Xmx1G'
If build problems occur (in rare cases the IntelliJ's internal compiler is more strict than plain Groovy), disable the 'Make' checkbox in the run config dialog.
If the problem persists, paste a screenshot of the run configuration you're using.

Resources