I am a beginner with Java, Maven, and Eclipse.
I have made a simple standalone Java program and generated a Maven package with Eclipse LUNA. When I began to debug the Java program, I found that breakpoints did not work. When setting the breakpoint, there will be a circle at the beginning of code line.
Now there was circle, but it had a line over the circle.
How can I execute debugging the Java program with Maven in Eclipse?
Do it like this:
a.Right click project.Then, Debug as -> Maven build ...
b.In the goals field put -Dmaven.surefire.debug test
c.In the parameters put a new parameter called forkMode with a value of never
Set your breakpoints down and run this configuration and it should hit the breakpoint.
If you are really saying "line over circle" then you have breakpoints there in eclipse and disabled.
Go to "Debug" view > Breakpoints and enable you should stop at your breakpoints then in your debug session
Related
Is it possible to open 2 or more projects, in different IntelliJ instances, and debug across them?
For example:
I start debugging on Project A. Project A calls a method in Project B. I want my debugger to continue on Project B on the other window.
I know a way to debug across multiple maven projects, is to add all the projects to the same IntelliJ instance. But I would like to know if there is a way to do it, without adding all projects to the same instance. To break up the projects in its own IntelliJ windows.
Yeah it is possible
First create a remote debug configuration: Edit configuration -> Remote.
You will see a command line argument which you have to copy and paste it to the script that you made to run your java file.
Keep in mind, to make sure your Project B doesnt starting running before your turn your debugger on, change suspend=n to suspend=y.
Once your parent java file runs go to the secondary idea window and run the remote configuration that you created in first step. If everything is right, your code will stop at the breakpoint.
I have a spring boot application. I use IntelliJ 13.
I want to launch my application in debug mode and debug it. I'm on Windows and I'd like to use shared memory. I would like to just be able to click the debug icon, or a single maven goal, and the application launches in debug mode and the IDE attaches the debugger. This is how I am used to debugging most of my java apps.
However, mixing spring-boot and IntelliJ seems to complicate things. IntelliJ seems to want to connect to the wrong process when I push the green "debug" button and I can't find a way to change the shared memory address that the green 'debug' button's functionality is determined to connect to.
The closest I've come is to add jvmoptions to the maven goal in pom.xml, and then if I add a Remote run configuration, IntelliJ lets me specify a shared memory address that matches what I wrote in the pom. This requires multiple clicks to launch the application and then debug it. It works, in a similar way that using notepad.exe to write code also works. Hence my question.
Is there a 1-step solution using shared memory?
Variation of this question:
Debugging jsp with spring-boot and IntelliJ
However the question and answers are limited to using sockets.
The problem was that IntelliJ was using the Maven goal spring-boot:run as the launch configuration, and trying to debug this causes the debugger to attach to the wrong process.
Setting a new launch configuration of type Application and pointing it at the project's class with the main() method resolves this issue.
Thanks to the commentors for suggesting that this was the way to go about it!
A one click solution (tested on IntelliJ IDEA 14.0.1) using Sockets :
Open Run/Debug Configurations, Add a new Configuration of type Remote
On the Before Lauch panel, add a Run Maven Goal with the command line command:
spring-boot:run "-Drun.jvmArguments=-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
The suspend=n option is important to avoid the Maven Goal to be locked waiting the debugger to connect.
After that you will be able to just lauch this debug task and your app will be launched and the debugger will be attached.
I am trying to put breakpoints in my code for some simple debugging but my program is not stopping or telling me if the breakpoints is reached. I use CRTL+SHIFT+B and the breakpoint is visible in blue (enabled) on the left side. I am using these breakpoints in my core project and running from desktop project. Am i missing something and/or how to fix this?
Did you check the
Menu -> Run -> Skip All Breakpoints
to see if it was checked? I ran into this once and it drove me crazy as well.
I am sometimes running into obscure problems with Gradle. Sometimes it helps if i am reading the source files or adding println statements to figure out what i can do and what the state is.
But i would really like to just place a breakpoint and list the internal state of variables. is that possible using Android Studio or IntelliJ ?
I would also love to ctrl-click to the DSL keywords so i can get some context.
Just placing a breakpoint and clicking "debug" from the list of gradle tasks does not work, it just runs the tasks without stopping.
You can't debug Gradle files. We may someday implement this, as it would obviously be a great thing, but it's a long ways off. We're in the process of adding more intelligence about syntax highlighting and analysis of build files. Well, actually, JetBrains is adding it to IntelliJ and we're picking it up. This will get better over the coming weeks and months.
Original source
1. Create a debugger
Run -> Edit Configurations
Add New Configuration
Add Remote configuration
2. Open debug mode
$ export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
3. Start debugger
$ ./gradlew someTask -Dorg.gradle.daemon=false #!important, disable daemon mode
4. Attach debugger
Set breakpoints
Start debug
5. Disable debug mode
$ unset GRADLE_OPTS
I have coded in c++ in visual studio for several years.
I am now working in java with eclipse.
the java programs are launched from a .bat file so I cannot breakpoint them to debug.
Without being able to step through my code i am finding it very hard to find the root cause of the error as the thrown exception is not usually the source of the problem.
How can I debug my code without access to breakpoints ?
You can find the main method, as suggested by Ben J, and run this from Eclipse. To pass arguments to it, edit the run configuration. e.g. Right-click on the main class, click "Run As" and then "Run Configurations...". Select the "Arguments" tab and enter whatever you need.
Or since you need to debug this, click "Debug As" and "Debug Configurations..." instead.
Use Maven or Ant to launch your programs, instead of a batch file. There is much better integration with Eclipse.