Saturday, November 5, 2011

Compile and Run java programs directly through Notepad++


I've always loved Notepad++,because of its ease of use,auto-indentation,syntax coloring and many other features,not found in the default Windows Notepad.
Today,I found an interesting technique,which allows you to Compile and Run java programs directly through Notepad++,without the need to open Command Prompt.
Follow the simple steps mentioned below:

  • Download Notepad++
  • I'm considering you have already downloaded java development kit(InShort: jdk).If not,download it from here
    Java development Kit
  • Once installed,open Notepad++.Open "Plugin" menu
    Plugin=>Plugin Manager=>show Plugin Manager
  • Find a plugin in the list,named NppExec,and click on it.Click Install button.
  • Now,Go to Plugins=>NppExec,and apply the following.

    1. Disable or uncheck "Console command history".
    2. Enable "save all files on execute".
    3. Enable "Follow $(CURRENT_DIRECTORY)".
  • Now,go to Plugins>NppExec>Execute

    1. Enter the following commands
      cd "$(CURRENT_DIRECTORY)"
      javac $(FILE_NAME)
    2. Then choose Save..and save it with a name Compile
    3. Choose option from the menu,and enter the following commands

      cd $(CURRENT_DIRECTORY)
      java $(NAME_PART)


      This time,save it with a name Run
    4. Similarly,Save another command Compile and Run

      cd $(CURRENT_DIRECTORY)
      javac $(FILE_NAME)
      java $(NAME_PART)
  • Now,the final step is adding these commands in our Macro menu.Go to Plugins>NppExec>Advanced options.
  • Enable "Place to the Macros submenu".
  • Select Compile from under the "Associated script:" menu,and click on Add/Modify button.Similarly,choose Compile from this menu,write Compile in the "Item name" field,and hit Add/Modofy button.Similarly,add the Compile and Run script.
  • Hit OK button,it will ask you to Restart Notepad++.
  • Restart Notepad++,open a java program,and compile it and run,using the commands under the Macro menu.


12 comments:

  1. Very Useful. Thanks for the info.

    ReplyDelete
  2. Worked for me... Best article ever !! :)

    ReplyDelete
    Replies
    1. Thanks,glad you liked it :)

      Delete
    2. Hi Manas ..am able to compile but not able to see the output .. :(

      Delete
  3. Thanks Admin,
    You solved my problem.......

    ReplyDelete
  4. Completely confused by this step...

    Choose option from the menu,and enter the following commands....

    What menu?

    Notepad++ 6.5.1

    ReplyDelete
  5. there is notepad++ compiler you can check it out
    downlod here

    ReplyDelete
  6. Thanks, it works as it expectated.

    ReplyDelete
  7. Hello, recently I have created "Java Plugin for Notepad++" that allows you to compile and run java in Notepad++.
    You can find more information here https://github.com/dominikcebula/npp-java-plugin

    ReplyDelete