问题
Since JavaFX has become OpenJFX and needs to be added as a dependency to your Maven project, debugging a OpenJFX application has become complicated. In this question it is already answered how to solve it for NetBeans. But IntelliJ works slightly different. The Ppom.xml has been setup according to this example.
How can you run an OpenJFX (JavaFX) application which is configured as a Maven project in debug mode in IntelliJ?
回答1:
If you would copy the addition of VM options in the pom.xml for javafx-maven-plugin as given by José Pereda here, you can run the application with 'mvn javafx:run@debug' and then manually attach it to the IntelliJ Debugger by go to the menu 'Run - Attach to process...' and the select your application.
However, if you want debugger and application to be started with a single click, IntelliJ is a but troublesome. You can create a Remote Debug configuration which first launches your application and the debugger serially. Or have Compound Configurations which does both in parallel. The problem is to get them synchronized.
I found the following solution. Make your application run as debug client and the IntelliJ debugger as server. The VM options for the javafx-maven-plugin in the pom.xml file should have 'server=n':
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<executions>
<execution>
<!-- Default configuration for running -->
<id>default-cli</id>
<configuration>
<mainClass>org.waninge.test.JFXTest</mainClass>
</configuration>
</execution>
<execution>
<!-- Configuration for debugging -->
<id>debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:8000,suspend=y</option>
</options>
<mainClass>org.waninge.test.JFXTest</mainClass>
</configuration>
</execution>
</executions>
</plugin>
Create a Maven Run Configuration in IntelliJ with 'javafx:run@debug' in the 'Command line'. Create a Remote Run Configuration with the following settings:
- Debugger mode: 'Listen to remote JVM';
- Transport: 'Socket';
- Host: as in the pom
- Port: as in the pom
Now the Remote Run Configuration will start a debug server waiting for clients. The Maven Run Configuration will connect to the debug server, or fail if the debug server isn't online.
Now, to get everything started with a single click, you can create a Compound Run Configuration and add the Maven and the Remote Run Configuration to it. Starting this configuration will launch the two in parallel, and you can debug your application.
来源:https://stackoverflow.com/questions/61474493/how-to-debug-a-maven-openjfx-application-in-intellij