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:
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:
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: