I spent sometime today trying to compile and then run Java using Notepad++ so I figured that I would write a guide explaining how to do it.
For those of you who don’t know Notepad++ is one of my favorite text editors.
Step 1) Download and install the Java JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html
Step 2) Setup your path variables
Step 2.1) Go to your control panel and search for path
Step 2.2) Click on edit the system environment variables
Step 2.3) Click on environment variables
Step 2.4) Find your path setting
Step 2.5) Click on your path variable and then click on the edit button
Step 2.6) At the end of your path variable add the following: “;C:\Program Files\Java\jdk%JDK-VERSION%\bin” where %JDK-VERSION% is your JDK version number. (You can also find this by browsing to c:/program files/java and looking at the folders there)
Step 3) Log off your computer and then log back in. (You can also reboot if you want, but that is unnecessary)
Step 4) Somewhere on your computer make a new text file and add the following to it:
cd /d “%1″
javac %2 -Xlint:all
if errorlevel 1 goto finish
java %3
:finish
pause
Step 5) Rename this file to CompileJava.bat (if the file name does not end it .txt before you rename you will need to do this first)
Step 6) Copy this file to C:/Program Files/Notepad++
Step 7) Hit the “F5″ key and type the following into the text field $(NPP_DIRECTORY)\CompileJava.bat “$(CURRENT_DIRECTORY)” “$(FILE_NAME)” “$(NAME_PART)”
Step 8 ) Click on save and name the command something like “CompileJava”, you can also set up a key command if you like.
Step 9) You can now access your command from the “Run” menu
Thats it, your now ready to create and run Java code from Notepad++! One important note though, only Java programs with default package will compile and run.



July 30th, 2011 on 4:31 am
I’ve searched the web for hours now, and nothing is working, but this came the closest. I can’t get the simplest program to compile and run. Any ideas?
Errors:
C:\Users\Carlos\Documents\Java>cd /d ô”C:\Users\Carlos\Documents\Java”?
The filename, directory name, or volume label syntax is incorrect.
C:\Users\Carlos\Documents\Java>javac “HelloWorld.java”
javac: invalid flag: ôHelloWorld.javaö
Usage: javac
use -help for a list of possible options
C:\Users\Carlos\Documents\Java>if errorlevel 1 goto finish
C:\Users\Carlos\Documents\Java>pause
Press any key to continue . . .
September 2nd, 2011 on 11:37 am
Hi Carlos, the issue here is that the quotes that you are using in your code are incorrect. Try replacing the quotes in your .bat file to be ” and not “ or ”.
October 4th, 2011 on 5:17 am
Thanks for the tips – here is weird thing. I am on Windows 7 64 bit, if I run the code I get the following errors:
java.lang.UnsupportedClassVersionError: testCompile : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: testCompile. Program will exit.
Exception in thread “main” <<< Process finished.
================ READY ================
If I run THE SAME EXACT thing in a command prompt window that I open, it works. Any ideas?
October 4th, 2011 on 5:18 am
I forgot to tell you that it compiles fine, it just won’t actually run the code.
October 30th, 2011 on 5:24 pm
i stuffed my path variables what are they ment to look like?