【问题标题】:I can't debug an application using netbeans 11 with JavaFX 12我无法使用带有 JavaFX 12 的 netbeans 11 调试应用程序
【发布时间】:2019-10-05 10:23:25
【问题描述】:

我已经下载了支持 java 12 的 netbeans 11 所以我按照 Gluon 网页上的步骤运行 JavaFX 和 Netbeans Non modules with maven > https://openjfx.io/openjfx-docs/#next-steps

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

运行项目 清理 javafx:ru​​n

但是没有指定调试项目。 有没有办法调试这个 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>

【问题讨论】:

    标签: javafx netbeans javafx-11 openjfx


    【解决方案1】:

    如果您看到javafx-maven-plugindocumentation,您可以向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>
    

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

    mvn clean javafx:run
    

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

    mvn clean javafx:run@debug
    

    启动调试模式。然后你会看到类似的东西:

    [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
    

    此时,您需要设置断点并将调试器从NetBeans -&gt; Debug -&gt; 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>
    

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

    【讨论】:

      【解决方案2】:

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

      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>
      
      

      注意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>
      

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

      【讨论】:

      • 无法使用 Apache NetBeans 12 + javafx maven 插件 0.0.4
      • @Birdasaur 为我使用 NetBeans 12.3 和 javafx-maven-plugin 0.0.4
      猜你喜欢
      • 2020-06-19
      • 2019-03-03
      • 2023-04-07
      • 2019-06-09
      • 2021-02-25
      • 2019-05-23
      • 2021-04-26
      • 2021-02-22
      • 1970-01-01
      相关资源
      最近更新 更多