我无法使用带有 JavaFX 12 的 netbeans 11 调试应用程序 [英] I can't debug an application using netbeans 11 with JavaFX 12

查看:50
本文介绍了我无法使用带有 JavaFX 12 的 netbeans 11 调试应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了支持 java 12 的 netbeans 11所以我按照 Gluon 网页上的步骤运行 JavaFX 和 Netbeans 非模块化与 maven >

单击确定",您将能够调试您的项目.

请注意,您还可以定义自定义 NetBeans 操作以使用运行"和调试"按钮.将 nbactions.xml 文件添加到项目的根目录,执行以下两个操作:

现在您可以使用 NetBeans 运行和调试按钮.

I've downloaded netbeans 11 with support for java 12 So I followed up the steps from the Gluon webpage running JavaFX and Netbeans Non modular with maven > https://openjfx.io/openjfx-docs/#next-steps

I have configured as showed in the instructions the action to run this app.

Run Project clean javafx:run

But there is nothing specified to debug the project. Is there a way to debug this javaFX project?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>SimonSaysGFX</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>12</maven.compiler.source>
        <maven.compiler.target>12</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>12.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>12.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>12.0.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>12</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.2</version>
                <configuration>
                    <mainClass>com.mycompany.simonsaysgfx.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <name>SimonSaysGFX</name>
</project>

解决方案

If you see the documentation of the javafx-maven-plugin, you can add some VM arguments to the run goal in order to debug your project in NetBeans.

However, to keep the usual run goal ready to just run the project and not debug, without commenting out the added options, we can add a second execution to the plugin.

Modify your plugin like this:

<plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>0.0.2</version>
    <executions>
        <execution>
            <!-- Default configuration for running -->
            <id>default-cli</id>
            <configuration>
                <mainClass>com.mycompany.simonsaysgfx.App</mainClass>
            </configuration>
        </execution>
        <execution>
            <!-- Configuration for debugging -->
            <id>debug</id>
            <configuration>
                <options>
                    <option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:8000</option>
                </options>
                <mainClass>com.mycompany.simonsaysgfx.App</mainClass>
            </configuration>
        </execution>
    </executions>
</plugin>

Now you can run from command line:

mvn clean javafx:run

to run as usual your application, and:

mvn clean javafx:run@debug

to start debug mode. Then you will see something like:

[INFO] --- javafx-maven-plugin:0.0.2:run (debug) @ Project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /path/to/project/target/classes
Listening for transport dt_socket at address: 8000

At this point, you need to set your breakpoints and attach a debugger from NetBeans -> Debug -> Attach Debugger to port 8000:

Click OK and you will be able to debug your projects.

Note that you can also define custom NetBeans actions to use the Run and Debug buttons. Add a nbactions.xml file to the root of your project, with this two actions:

<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <action>
        <actionName>run</actionName>
        <goals>
            <goal>clean</goal>
            <goal>javafx:run</goal>
        </goals>
    </action>
    <action>
        <actionName>jlink</actionName>
        <goals>
            <goal>clean</goal>
            <goal>javafx:jlink</goal>
        </goals>
    </action>
    <action>
        <actionName>debug</actionName>
        <goals>
            <goal>clean</goal>
            <goal>javafx:run@debug</goal>
        </goals>
    </action>
</actions>

Now you can use NetBeans run and debug buttons.

这篇关于我无法使用带有 JavaFX 12 的 netbeans 11 调试应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆