1

如何从cmd Notepad++ 的插件 NppExec正确运行 JavaFX 应用程序?我之前java $(NAME_PART)在 Notepad++ 插件 NppExec(它基本上是一个内置的 cmd)上使用了该命令来运行 java,它适用于基于 swing 的程序。但是,当我使用该命令运行 JavaFX 应用程序时,我的 Notepad++ 窗口似乎失去焦点,好像打开了一个新窗口但没有出现任何内容。

编辑:在从 cmd 测试相同的命令后,我发现问题出在 Notepad++ 插件 NppExec 上。运行 JavaFX 应用程序时,NppExec 的功能似乎与 cmd 不同。

我用来测试的代码(最初是从http://docs.oracle.com/javase/8/javafx/api/javafx/application/Application.html获得的)将根据上面的编辑进行更新:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class MyApp extends Application {
    public void start(Stage stage) {
        Circle circ = new Circle(40, 40, 30);
        Group root = new Group(circ);
        Scene scene = new Scene(root, 400, 300);

        stage.setTitle("My JavaFX Application");
        stage.setScene(scene);
        stage.show();
    }
    //not required but recommended
    public static void main(String[] args) {
        launch(args);
    }
}
4

2 回答 2

3

回答我自己的问题。

从 NppExec 的手册中,

- NppExec is not a command interpreter. NppExec does not understand such commands as 'copy', 'call', 'for' and so on because it is neither a "real" console nor a console emulator. However, NppExec has its own internal implementation of such commands as 'cls', 'cd', 'dir', 'echo', 'set' ('env_set') and introduces other, specific, commands. Also you can use "cmd /c <command>" to execute any cmd's command inside NppExec.

使用cmd /c java $(NAME_PART)而不是java $(NAME_PART)成功运行。

仍然不确定为什么简单地调用java $(NAME_PART)对非 JavaFX 程序有效,但对 JavaFX 程序失败,但我认为问题不属于这里。

于 2014-09-12T00:48:25.820 回答
0

I got this to work:

npp_save
cd "$(CURRENT_DIRECTORY)"
C:\Program Files\Java\jdk1.8.0_131\bin\javac "$(FILE_NAME)"
cmd /c cd "$(CURRENT_DIRECTORY)" && java "$(NAME_PART)"

The key was to be able to run two commands on one line. The && expression does this. In case you were wondering, the second command will not run if the first command is not executed successfully.

Make sure you have Java in your environment variables on your computer. If you don't then you will have to supply the full path to the Java executable.

npp_save
cd "$(CURRENT_DIRECTORY)"
C:\Program Files\Java\jdk1.8.0_131\bin\javac "$(FILE_NAME)"
cmd /c cd "$(CURRENT_DIRECTORY)" && "C:\Program Files\Java\jdk1.8.0_131\java.exe" "$(NAME_PART)"
于 2017-07-17T02:04:07.440 回答