Learn the powerful enterprise adaptable database:

Getting Started With ADABAS & Natural

Monday, May 6, 2013

Notepad++ NppExec Add Java Compiler


1) If you haven't installed NppExec PlugIn, follow this tutorial, http://setup-steps.blogspot.com/2013/05/notepad-adds-plug-in-nppexec.html, before proceeding to the next step.

2) Configure the NppExec Plugin:

Go to Plugins > NppExec and apply the followings:
1. Disable "Console Command History"
2. Enable "Save all files on execute"
3. Enable "Follow $(CURRENT_DIRECTORY)"


3) Add Compile command:
3.1. Go to Plugins > NppExec > Execute...
3.2. Choose “Cancel” if  a Save File… dialog box appears
3.3. Enter the following command:
cd “$(CURRENT_DIRECTORY)”
javac $(FILE_NAME)



3.4. Click Save. Type the name as "Compile".




4) Add Run command:

cd "$(CURRENT_DIRECTORY)"
java)$(NAME_PART)


5) Add Compile and Run command:

cd "$(CURRENT_DIRECTORY)"
javac $(FILE_NAME)
java $(NAME_PART)




6) Add the Execute Command Names as menu.
6.1) Go to NppExec Advance Options:



6.2)  enable "Place to the Macros submenu".


6.3) Then select “Compile” from under the “Associated script:” menu, and click the
“Add/Modify” button:



6.4) Repeat this process for the other two scripts, be careful to type the names “Run” and
“Compile and Run” in the “Item name:” box before hitting the Add/Modify button.


7) Restart Notepad++.

8) Test by creating Test.Java file.

public class Test {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

9) Go to menu  Macro/Compile.


9.1) In case you get an error like below:


9.1.1) Change your command as follows:


cd $(CURRENT_DIRECTORY)
C:\Program Files\Java\jdk1.7.0_21\bin\javac $(FILE_NAME)



It could be caused by Windows not knowing the path to javac program (possibly true when you are using Notepad++ Portable Version, because it is running in its own memory container).

10) A successful Compile Command would result as follow:


11) A successful Compile and Run Command would result as follow:





Reference:
1) http://www.cs.auckland.ac.nz/compsci101s1c/resources/Notepad/Notepad++.pdf
2) http://blog.sanaulla.info/2008/07/25/using-notepad-to-compile-and-run-java-programs/

3 comments:

  1. Thanks :) very good info. Now Runs!!!

    ReplyDelete
  2. Which file does the "C:\Program Files\Java\jdk1.7.0_21\bin\javac $(FILE_NAME)" get saved into? I want to edit that file to update the JDK path. I have many machines where I need to update the line, so I want to know which file it is, and edit that one. Then copy it to other machines.

    ReplyDelete
    Replies
    1. If you have installed some other version of jdk just open the path where your jdk is installed .. like in the above path which you gave "jdk1.7.0_21" as the jdk 7 version . simply edit this part with ur version of jdk .. Hope it works . If you still have some other problem mail me to zuhakk@gmail.com...

      Delete