Click here to Skip to main content
13,146,742 members (79,742 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

10.4K views
14 bookmarked
Posted 19 Sep 2016
MIT

Compile and execute Java, C# and PHP from your favourite text editors - Sublime Text 2 and Notepad++

, 19 Sep 2016
Rate this:
Please Sign up or sign in to vote.
Compile and Execute Java, C#, and PHP From Your Favorite Text Editors for REPL (Read-Evaluate-Print-Loop) use cases


Note: The instructions below are based on Windows environment, but are adaptable for Mac/Linux environments.

Sublime Text 2

Compile and execute Java from Sublime Text 2:

Assuming JDK to be present, else you need to download that first. You can download it from this link: JDK8
 
Step 1. Add the directory that contains your "javac" executable to "PATH" environment variable:
Open "Command Prompt" with administrator rights i.e "Run as administrator".
Execute the following command: SETX /M PATH "%PATH%;C:\Program Files\Java\jdk1.8.0_20\bin"
My javac executable was located in: C:\Program Files\Java\jdk1.8.0_20\
Note: The SETX command will truncate the path to 1024 characters, so it could be destructive.
 
Alternative approach :
1. Press Win+Pause key.
2. Follow as directed in the screenshot below:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Step 2. Customize Sublime's build configuration for Java:
1. Click on Preferences -> Browse Packages
2. Navigate to Java Folder -> JavaC.sublime-build
3. Modify the contents of this file as:
   {
      "cmd": ["javac", "$file"],
      "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
      "selector": "source.java"
   }
change to
   {
      "cmd": ["javac $file && java $file_base_name"],
      "shell": true,
      "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
      "selector": "source.java"
   }
Note: I have modified the value for "cmd" key and changed it to first compile/build the java program with "javac" executable and then run it with "java" executable.
 
Step 3. Restart Sublime Text.
 
Step 4. Create/open a Java file and press Ctrl+B to build and execute the java program. See the example below:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Execute PHP from Sublime Text 2:

Assuming PHP to be present, else you need to download that first. You can download it from http://windows.php.net/download/ or http://php.net/downloads.php. PHP is already installed with WAMP, XAMPP and other stacks.
 
Step 1. Add the directory that contains your "php" executable to "PATH" environment variable.
Follow the same steps as demonstrated above.
My "php" executable was located in: C:\Servers\xampp\php
 
Step 2. Create a new build system for PHP. Follow as directed in the screenshot below:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Step 3. Clicking "New Build System..." will open a new file named "untitled.sublime-build". Replace the contents of this file with:
{
    "cmd": ["php $file"],
    "shell": true,
    "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
    "selector": "source.php"
}
 
Step 4. Press Ctrl+S to save this file, Rename "untitled.sublime-build" to "PHP.sublime-build"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Step 5. Restart Sublime Text.
 
Step 6. Create/open a PHP file and press Ctrl+B to build and execute the PHP script. See the example below:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Compile and execute C# from Sublime Text 2:

Assuming .NET framework to be present, else you need to download that first. You can download it from https://www.microsoft.com/en-in/download/details.aspx?id=30653.
 
Step 1. Add the directory that contains your "csc" executable to the "PATH" environment variable.
Follow the same steps as demonstrated above.
My "csc" executable was located in: C:\Windows\Microsoft.NET\Framework64\v4.0.30319
 
Step 2. Create a new build system for C#. Click on Tools->Build System->New Build System... in Sublime Text.
 
Step 3. Clicking "New Build System..." will open a new file named "untitled.sublime-build". Replace the contents of this file with:
{
    "cmd": ["csc $file && $file_base_name"],
    "shell": true,
    "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
    "selector": "source.cs"
}
 
Step 4. Press Ctrl+S to save this file, Rename "untitled.sublime-build" to "CSharp.sublime-build"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Step 5. Restart Sublime Text.
 
Step 6. Create/open a C# file and press Ctrl+B to build and execute the C# program. See the example below:

























 

Notepad++

Step 1. Install NPPExec plugin. Follow as directed in the screenshots below:

 
 

 

 

 

 

 

 

 

 

 

 

Step 2. (Optional) Configure NPPExec plugin to not display internal messages.

 

 

 

 

 

 

 

 

 

 

Compile and execute Java from Notepad++:

Once NPPExec plugin is installed and configured, we can move on to create "Execute" script for compiling and executing Java.
 
Step 1. Add the directory that contains your "javac" executable to "PATH" environment variable.
Follow the steps as demonstrated at the start of this article to configure the PATH.
 
Step 2. Create an "Execute" script to compile and run java.






















Step 3. Write the following commands in the "Command(s)" section and type in "JavaExecute" (can be any name here) in the "Script Name" section:
cd $(CURRENT_DIRECTORY)
javac $(FILE_NAME)
java $(NAME_PART)
For more information on Notepad++ environment variable, refer to this link: http://docs.notepad-plus-plus.org/index.php/External_Programs
 
 
 






















Step 4. Configure the "JavaExecute" script created above, to be listed as a macro. Follow as directed in the screenshots below:
 






















Step 5. Restart Notepad++.

Step 6. Once the "JavaExecute" script is listed as a macro, we need to map a keyboard shortcut to execute this macro so that we can compile and execute java directly. Follow as directed in the screenshots below:
 






















Step 7. Once the shortcut has been assigned, create/open a Java file and press Ctrl+Shift+B to build and execute the java program. See the example below:





















 

Execute PHP from Notepad++:

Once NPPExec plugin is installed and configured, we can move on to create "Execute" script for compiling and executing Java.
 
Step 1. Add the directory that contains your "php" executable to "PATH" environment variable.
Follow the steps as demonstrated at the start of this article to configure the PATH.
 
Step 2. Create an "Execute" script to run PHP. Click on Plugins-NppExec-Execute.. (Refer to screenshot in Step#2 in Compile and execute Java from Notepad++ section)
 
Step 3. Write the following commands in the "Command(s)" section and type in "PHPExecute" (can be any name here) in the "Script Name" section:
cd $(CURRENT_DIRECTORY)
php $(FILE_NAME)

 

























Step 4. Configure the "PHPExecute" script created above, to be listed as a macro. Follow as directed in the screenshots below. For bringing up the NppExec Advanced Options dialog, click on Plugins-NPPExec-Advanced Options... (Refer to screenshot in Step#4 in Compile and execute Java from Notepad++ section)
 
























Step 5. Restart Notepad++.

Step 6. Once the "PHPExecute" script is listed as a macro, we need to map a keyboard shortcut to execute this macro so that we can execute PHP directly. Follow as directed in the screenshots. For bringing up the Shortcut Mapper dialog, click on Settings-Shortcut Mapper... (Refer to screenshot in Step#6 in Compile and execute Java from Notepad++ section):
 
























Step 7. Once the shortcut has been assigned, create/open a PHP file and press Ctrl+Shift+C to execute the PHP program. See the example below:
 























 

Compile and execute C# from Notepad++:

Once NPPExec plugin is installed and configured, we can move on to create "Execute" script for compiling and executing Java.
 
Step 1. Add the directory that contains your "csc" executable to "PATH" environment variable.
Follow the steps as demonstrated at the start of this article to configure the PATH.
 
Step 2. Create an "Execute" script to compile and execute C#. Click on Plugins-NppExec-Execute.. (Refer to screenshot in Step#2 in Compile and execute Java from Notepad++ section)
 
Step 3. Write the following commands in the "Command(s)" section and type in "CSharpExecute" (can be any name here) in the "Script Name" section:
cd $(CURRENT_DIRECTORY)
csc $(FILE_NAME)
$(NAME_PART)

 
























Step 4. Configure the "CSharpExecute" script created above, to be listed as a macro. Follow as directed in the screenshots below. For bringing up the NppExec Advanced Options dialog, click on Plugins-NPPExec-Advanced Options... (Refer to screenshot in Step#4 in Compile and execute Java from Notepad++ section)
 























Step 5. Restart Notepad++.

Step 6. Once the "CSharpExecute" script is listed as a macro, we need to map a keyboard shortcut to execute this macro so that we can compile and execute C# directly. Follow as directed in the screenshots. For bringing up the Shortcut Mapper dialog, click on Settings-Shortcut Mapper... (Refer to screenshot in Step#6 in Compile and execute Java from Notepad++ section):
 























Step 7. Once the shortcut has been assigned, create/open a C# file and press Ctrl+Shift+N to compile and execute the C# program. See the example below:
 

License

This article, along with any associated source code and files, is licensed under The MIT License

Share

About the Author

Robin Rizvi
Software Developer Databorough India
India India
Currently working as software developer for Databorough India - Division of Fresche Legacy.

Developing for the open-source community and writing articles is my way of thanking the community. I have developed commercial as well as non-commercial/open-source projects for the web and windows as my work and hobby. Just trying very hard so that someday I could contribute a little for this world. I would like to send out my regards to all for your rating and comments because these comments keep me going. Thank you all.

Certifications:
Microsoft Certified Professional (Programming in C#)
Microsoft Certified Professional (Programming in HTML5 with JavaScript and CSS3)

You may also be interested in...

Comments and Discussions

 
QuestionC# + Notepad++ alternative Pin
Oleg Shilo19-Sep-16 15:22
memberOleg Shilo19-Sep-16 15:22 
AnswerRe: C# + Notepad++ alternative Pin
Robin Rizvi19-Sep-16 23:07
memberRobin Rizvi19-Sep-16 23:07 
AnswerRe: C# + Notepad++ alternative Pin
Robin Rizvi19-Sep-16 23:09
memberRobin Rizvi19-Sep-16 23:09 
GeneralRe: C# + Notepad++ alternative Pin
Oleg Shilo20-Sep-16 0:49
memberOleg Shilo20-Sep-16 0:49 
GeneralRe: C# + Notepad++ alternative Pin
Robin Rizvi20-Sep-16 1:07
memberRobin Rizvi20-Sep-16 1:07 
GeneralRe: C# + Notepad++ alternative Pin
Oleg Shilo20-Sep-16 1:21
memberOleg Shilo20-Sep-16 1:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 19 Sep 2016
Article Copyright 2016 by Robin Rizvi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid