How to run Java applications in Notebook++ version 7.9
I want to run SimpleCalc.java in Notpad++ ,but it showed error. I have run SimpleCalculator.java under NetbeansProjects directory successfully. How to debug this running java application process?
We cannot be expected to be Java experts and thus debug any Java problems you might be having – as a forum for a text editor, doing programming debugging is off topic.
From the Notepad++ standpoint, it appears you are using the NppExec to run
javacon the active file. It’s using the command
javac SimpleCalc.javato call that. If you were at a normal command prompt (cmd.exe or powershell), would that command be sufficient? Do you know what command-line that NetbeansProjects uses when calling your SimpleCalc.java ?
I haven’t done any java recently, but a few years ago, I played around with it some. At that time, I had created a java-compile and java-compile-and-run script for NppExec:
NPP_SAVE cd "$(CURRENT_DIRECTORY)" javac "$(FILE_NAME)"
compile then run
NPP_SAVE cd "$(CURRENT_DIRECTORY)" javac "$(FILE_NAME)" java -classpath "$(CURRENT_DIRECTORY)" "$(NAME_PART)"
You will notice that I do slightly more than just run
javac: first I make sure the file is saved (otherwise
javacwill see the last-saved version, which might not match what I have open in Notepad++ if I’ve forgotten to save first); second, I change into the same directory that the
.javafile is saved in (NppExec doesn’t guarantee it will set up its environment in the same folder); then third, I use
javacto compile the
Also, looking briefly at your error message in the console, it says “class SimpleCalculator is public, should be declared in a file named SimpleCalculator.java”, but your file is called
SimpleCalc.java. I don’t remember enough of my java to be sure, but a quick google told me that “the public class name must match the file name. Inner, non public, class names may differ.” – this strongly tells me that you should rename the file
SimpleCalculator.java. Notice, you even say,
I want to run SimpleCalc.java in Notepad++ ,but it showed error. I have run SimpleCalculator.java under NetbeansProjects directory successfully.
You said that you have the file called
SimpleCalc.javain Notepad++, but you had a file called
SimpleCalculator.javawhen you ran it under Netbeans. That lends strength to the suggestion that you should try running it with the filename and the public class name matching.
If you have more questions that are specific to Notepad++ and NppExec, feel free to ask follow ups.
@PeterJones As per your suggestion, I renamed the file to SimpleCalculator.java.
Please tell me in NppExec\execute window, are there any errors in writing command syntax? See the following picture.
I gave you the literal contents of the script. You did not need to manually put in the values.
I actually like this name “Notebook++”. It looks fresh!
Sorry for off-topic.😀
This post is deleted!
@PeterJones I successfully implemented the SimpleCalculator java program( by moving its locations to Documents folder) under NppExec plugin and obtained the desired result in Notepad++