Maven build debug in Eclipse - java

I want to debug Eclipse build with tests. I tried to run it by Run > Debug Configurations > Maven Build. In Base directory is my Maven repo directory with pom.xml file, in goals 'clean install'. When I click on debug Eclipse starts build, run tests but it doesn't stops on breakpoints.

Easiest way I find is to:
Right click project
Debug as -> Maven build ...
In the goals field put -Dmaven.surefire.debug test
In the parameters put a new parameter called forkCount with a value
of 0 (previously was forkMode=never but it is deprecated and doesn't work anymore)
Set your breakpoints down and run this configuration and it should hit the breakpoint.

if you are using Maven 2.0.8+, then it will be very simple,
run mvndebug from the console, and connect to it via Remote Debug Java Application with port 8000.

probleme : unit test result are not the same runing with eclipse and maven due ti order of library used by eclipse and maven.
In my case the test was success with maven but i want to debug my unit test using eclipse, so
the most easy way to debug unit test class with eclipse and runing maven is :
1) mvn -Dtest=MySuperClassTest -Dmaven.surefire.debug test ==> it will listen to the 5005 port (default port)
2) Go to eclipse, open a debug configuration, add a new java remote application and change the port to 5005 and debug
3) of course you must add break point somewhere in the class that you want to debug

The Run/Debug configuration you're using is meant to let you run Maven on your workspace as if from the command line without leaving Eclipse.
Assuming your tests are JUnit based you should be able to debug them by choosing a source folder containing tests with the right button and choose Debug as... -> JUnit tests.

Related

Eclipse Java Cucumber debug - how can I configure and run debug in cucumber maven project?

How can I configure Eclipse to run debug on a cucumber project?
I put breakpoint in given condition from specific "Step" java class and I have created maven build profile like as picture attachment but debugging doesn't work.
Thanks!
You are running it by maven commond like:
mvn clean install
But you need to run it using junit or testng.
Put an debug point in your step defination and run the project as junit/testng in debug section
You need to use install TestNG or Junit testing frameworks and use them in the run configurations will help to debug the cucumber test.
For TestNG, once after you install the software using install new software in Eclipse. In the TestNG Run Configurations give the Testng.xml file in the Suite field

Use IDEA Run/Debug Configuration to debug Gradle web app with Jetty plugin

What's the problem?
Is it possible to debug a Gradle web app running via Jetty plugin (using jettyRun or jettyRunWar) by using a IntelliJ IDEA Run/Debug Configuration?
I know that it is possible (I've done it before) to do it with Maven/Tomcat7 plugin and creating a simple Maven Run/Debug Configuration with the clean package tomcat7:run goals.
I've tried to create a Gradle Run/Debug Configuration with the clean jettyRunWar tasks. If I Run the configuration, everything works well. But the Debug option is not working as expected: the application actually runs, but debugger won't connect.
However, I did manage to debug the project by running on debug mode externally, like this:
$ export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=n"
$ ./gradlew clean jettyRunWar
And then creating a Remote Run/Degug Configuration with all the default configurations except the port, which was set to 9999.
But that's not the solution I was looking for. I want to be able to debug the project by only clicking a button. Am I missing something?
Not in the mood to read everything? Here's an example
I've created a simple IDEA/Gradle/Jetty web app using Jersey available on Github here. The problem can be reproduced by:
Cloning the repository
Importing it on IDEA
Creating a Gradle Run/Debug Configuration for the root project with the clean jettyRunWar tasks
Debug using the configuration
The debugger won't connect and breakpoints won't work.
I am using:
IntelliJ IDEA Community Edition 2016.1.3 (OS X)
Gradle 2.7 (a wrapper is available on the Git repository, so it doesn't matter)

Maven build outside eclipse, very time consuming

My current Setup:
I have Ecliple Mars installed on Windows 10
I have some repositories checked out in my Project explorer which I basically use for any code changes, debugging purpose.
I have tomcat installed in C directory and have its path configured in the Servers section of eclipse.
So, every time I do any code changes in eclipse, I manually go into the eclipse workspace, and do the maven build using the following commandmvn -Plocal -DskipTests=true clean install, and then manually copy the war generated in the target folder into the webapps directory of my tomcat.
After doing all these, I start my tomcat in debug mode catalina jpda start and then setup Remote Java Application in eclipse for a particular module.
I can then setup breakpoints and see the changes in the debugger.
I am wondering , all of the above steps are time consuming if I have to do frequent code changes and then debug something in Debug mode in eclipse as I have to repeat steps 4 to 6 again and again for any code changes.
Could anyone tell me if there is a quick way to achieve the same goal?
You can run application dirrectly from maven via maven-{your_servlet_container}-plugin (maven-tomcat-plugin, maven-jetty-plugin, etc.). you can also specify debug mode there, so all you need to do is just run maven and connect in eclipse to remote app.
set ENV variable for always run maven in debug:
set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
(unset by setting this value to empty string)
with env variable:
mvn -Plocal -DskipTests=true clean tomcat7:run
or run mvnDebug:
mvnDebug -Plocal -DskipTests=true clean tomcat7:run
If you have your tomcat configured with eclipse properly, then you don't need to perform all these steps. I am not sure if you want to automate all these steps from outside. if yes, then either you can automate above steps with writing all in a batch file & triggering all steps with it (not a standard way) or using maven plugins to automate most of these steps.
Hope this information will help...

How to debug maven tests remotely

I have a maven project. I want to debug tests that run during the project assembly. I run maven from cli
mvnDebug -DforkCount=0 test
Then I could successfully connect with remote debugger to the running jvm from Intellij. All necessary breakpoints are set. But it wouldn't stop at the breakpoints. Build successful and that is all.
This command works properly though
mvn -Dmaven.surefire.debug test
But I need to do it with the first.
I did not override plugin configuration so version 2.12 was used. The option that I needed was -DforkMode=never. Since 2.14 this option is deprecated and -DforkCount=0 should be used instead. http://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html
You need the debugForkedProcess option to surefire.

How to debug tests from a Maven build in Eclipse?

How is it possible to start a Maven build and let the tests appear in the debug perspective of Eclipse?
A package or install is meant to be an atomic action that really shouldn't be stopped for debugging (unless you're debugging a maven plug-in). You ought to be able to debug the tests by selecting the Eclipse project and doing a "Debug As -> JUnit Test", though.
How to configure it:
Create a new Java project in Eclipse. Let's call it "Maven debugger project". It's a dummy project and is not intented to contain any code.
Create a new debug configuration. Let's call it "Maven debug launch". In the Connect tab, enter "localhost" in the Host field and "5005" in the Port field, which is the port where the Surefire plugin communicates with a debugger. Choose "Standard (Socket Attach)" in Connection Type. In the Source tab, add the projects you want to debug.
How to use it:
You can now set breakpoints in your test code.
Start your "Maven debug launch" in debug
Start your Maven build with the "-Dmaven.surefire.debug" option
I found that interesting solution here, and it was useful to me (which mean I tested it, and it worked), so I wanted to share it.
If you run the Maven build with the Ecplise Maven Plugin :
Place the debug point in java code
Right click on your pom.xml or your project in Eclipse and Select "Debug As" and then "Maven Install" or If you want an other Maven goal Select "Maven build..."

Categories