我无法使用NetFX 11和JavaFX 12调试应用程序

Ale*_*lex 4 netbeans javafx openjfx javafx-11

我已经下载了支持Java 12的netbeans 11,所以我从运行JavaFX和Netbeans Non module with Maven的Gluon网页上进行了后续操作> https://openjfx.io/openjfx-docs/#next-steps

我已按照说明中的说明配置了运行此应用的操作。

运行Project clean javafx:run

但是没有指定任何调试项目的内容。有没有办法调试这个javaFX项目?

<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>
Run Code Online (Sandbox Code Playgroud)

小智 12

何塞的回答很好。再往前走一点。

pom.xml设置 address=${jpda.address}而不是address=*:8000

    <execution>
        <!-- Configuration for debugging -->
        <id>debug</id>
        <configuration>
            <options>
                <option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
            </options>
            <mainClass>cz.masci.mvcpattern.mvc.App</mainClass>
        </configuration>
    </execution>

Run Code Online (Sandbox Code Playgroud)

请注意 set server=n,否则应用程序将无法启动。

在调试操作设置jpda.listen=true属性中

   ...
    <action>
        <actionName>debug</actionName>
        <goals>
            <goal>clean</goal>
            <goal>javafx:run@debug</goal>
        </goals>
        <properties>
            <jpda.listen>true</jpda.listen>
        </properties>
    </action>
Run Code Online (Sandbox Code Playgroud)

那么你就不需要再附加调试器了。Netbeans 为您做到了。


Jos*_*eda 7

如果您看到的文档,则javafx-maven-plugin可以在run目标中添加一些VM参数,以便在NetBeans中调试项目。

但是,为了使通常的run目标只是准备好运行项目而不调试,而不必注释掉添加的选项,我们可以向插件添加第二次执行。

像这样修改您的插件:

<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>
Run Code Online (Sandbox Code Playgroud)

现在您可以从命令行运行:

mvn clean javafx:run
Run Code Online (Sandbox Code Playgroud)

以照常运行您的应用程序,并且:

mvn clean javafx:run@debug
Run Code Online (Sandbox Code Playgroud)

启动调试模式。然后,您将看到类似以下内容:

[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
Run Code Online (Sandbox Code Playgroud)

此时,您需要设置断点并将调试器从附加NetBeans -> Debug -> Attach Debugger到端口8000:

调试器

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

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

<?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>
Run Code Online (Sandbox Code Playgroud)

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