javanotepad++nppexec

Java compile and run using notepad++ and nppexec


Please keep in mind that compiling in the windows shell works, so there is little (if not zero) possibility of this issue being a PATH issue.

I have spent a lot of time research how to do this, and all the results I found online say that you can do:

NPP_SAVE
javac $(FILE_NAME)
java $(NAME_PART)

but that does not work for me. In the NPP_EXEC console, I can type java, and I get the normal results as I would from cmd, but any time I type javac, I get the dreaded error code 2 error:

================ READY ================
javac
javac
CreateProcess() failed with error code 2:
The system cannot find the file specified.

================ READY ================

Edit

I must clarify some confusion:

  1. This solution should run in a single script. The goal is to be able to change code, press a hotkey combination (think F5 in Visual Studio) and it builds/compiles and runs.
  2. The actually issue, iirc, was that notepad++ is not recognizing javac for some reason..

Sorry for the confusion...


Solution

  • I finally, after 5+ hours of googling and trial and error, have a working NPP Exec script that will compile and run a java program without leaving notepad++.

    NPP_SAVE
    cmd /K (javac "$(FULL_CURRENT_PATH)" && exit) || exit
    cmd /K (cd /D "$(CURRENT_DIRECTORY)" && java $(NAME_PART) && exit) || exit
    

    The only thing left would be finding a way to do the above, without having to call and send parameters to cmd, all in notepad++ and nppexec.

    As noted in the comment below, if you're using a package, you will need to edit the second line accordingly. If your package name is the same as your file name, the below should work:

    cmd /K (cd /D "$(CURRENT_DIRECTORY)" && java -cp .. $(NAME_PART).$(NAME_PART) && exit) || exit