How do I compile in debug mode? (netbeans, java, maven)

49,297

Solution 1

From what I understand, you want debug in the compilation- not maven in debug mode.

Using mvn to compile, use debug mode through following way:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>8</source>
        <target>8</target>
        <debug>true</debug>
        <debuglevel>lines,vars,source</debuglevel> 
    </configuration>
</plugin> 

debuglevel can be any of the three values entered in CSV format To highlight, debug and debuglevel are important nodes included in the maven.

Hope it helps in some way.

Reference: maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

Solution 2

You can debug any Maven goal in NetBeans going to /Project Properties/Actions/, select the goal you wan to debug, in the last option Set Properties choose Add, and then select Debug Maven build.

Solution 3

Are you running Maven in debug mode?

To run Maven in debug mode, use the command mvnDebug instead of mvn to build your project and then attach to it using your IDE. Debug breakpoints should be hit.

I've done this with Eclipse, mostly when trying to debug my own annotation processors, but it's also handy for debugging Maven plugins.

I'd imagine debugging a JPA processor would not be trivial - you might be better off looking at the whole error message again or posting it in your question.

Solution 4

You need to have the jpda.listen=maven property set.

In Netbeans 8+:

1. Select the module you want to debug when building.

2. Right-click to open the context menu, and select Properties.

3. Select the Actions category.

4. Then select the Clean and build project Action.

5. Under the Set Properties section, select Add > Debug Maven Build.

6. Click the OK button to close and save your settings.

Now you should be able to set breakpoints and debug maven plugins and dependencies.

Share:
49,297
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I am facing annotation/persistence errors in a project and the persistence library throws a

    NullPointerException when trying to resolve the entities (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.discoverMappedSuperclassesAndInheritanceParents(EntityAccessor.java:224)).

    How do I debug errors like these to find more about the cause of the error?

    Setting a breakpoint in EntityAccessor and compiling for debug doesn't work, the compiler itself seems to be not running in debug mode.

    I am using Netbeans / Java / Maven.

  • ibelcomputing
    ibelcomputing almost 9 years
    "From what I understand, you want debug in the compilation- not maven in debug mode." Exactly. I landed here looking for the later, OP wanted a solution for the former. Prunge's answer covers that.
  • Patricia
    Patricia over 8 years
    How should I run it, so I can attach to it from Netbeans? Question here: stackoverflow.com/q/33246407/1735836
  • zygimantus
    zygimantus about 8 years
    But I am still getting the message that I need to set "-g option", maybe you know how to do that?