ATH
ATH

Reputation: 43

How to run JavaFX application from Notepad++? (Only runs as .jar file)

How do you correctly run a JavaFX Application from cmd Notepad++'s plug-in, NppExec? I previously used the command java $(NAME_PART) on the Notepad++ plugin NppExec (which is basically a built-in cmd) to run java which worked fine for swing-based programs. However, when I use that command to run a JavaFX Application, my Notepad++ window seems to lose focus as if a new window was opened but nothing appears.

EDIT: I discovered the problem lies in the Notepad++ plugin NppExec after testing the same command from the cmd. NppExec doesn't seem to function the same as the cmd when running JavaFX Applications.

The code I am using to test (which was originally obtained from http://docs.oracle.com/javase/8/javafx/api/javafx/application/Application.html) will be updated according to the edits above:

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);
    }
}

Upvotes: 1

Views: 3418

Answers (2)

JackCarmichael
JackCarmichael

Reputation: 45

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)"

Upvotes: 0

ATH
ATH

Reputation: 43

Answering my own question.

From NppExec's manual,

- 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.

Using cmd /c java $(NAME_PART) rather than java $(NAME_PART) to run successfully worked.

Still unsure why simply calling java $(NAME_PART) works for non-JavaFX programs but fails for JavaFX programs but I don't think the issue belongs here.

Upvotes: 3

Related Questions