Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Notepad++ to compile Java code

Tags:

I've been trying to set up Notepad++ as a little Java environment, mainly for learning Java as I was having some difficulty getting a simple program to work with NetBeans, unfortunately all the advice on setting up Notepad++ to call the Java code is not working.

I guess notepad++ has changed or the Java development Kit has been massively modified because all examples I have used result in errors, even though there is little room for error.

to begin I found this site: http://blog.sanaulla.info/2008/07/25/using-notepad-to-compile-and-run-java-programs/

this is the code to run Javac to compile the code:

javac “$(FILE_NAME)” 

and

java “$(NAME_PART)” 

to run the resulted byte code, however this has absolutely no success at all anymore. Java is properly setup and I can call the Java program to do its thing through CMD.

Using a plugin called npp and called through F6 and run with this code (given in the comments) succeeds in compiling the Java program into the correct .class file, however the command failed in running the program

cd “$(CURRENT_DIRECTORY)” javac $(FILE_NAME) java $(NAME_PART) 

errors from the console in Notepad++ are:

java.lang.NoClassDefFoundError: first Caused by: java.lang.ClassNotFoundException: first   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: first.  Program will exit. Exception in thread "main" 

I figured setting up Notepad++ to compile and run the code would be easy and fun, but its seems all documentation on the internet is outdated as nothing works.

I would like a easy way to compile and run Java code from within Notepad++

I could just used CMD but i'd rather it be more integrated into notepad++

Thanks for any possible help. cheers :)

EDIT: I'm using the latest version of Java, notepad++ and have Windows 7

EDIT 2: the code:

 //A Very Simple Example  class ExampleProgram {     public static void main(String[] args){          System.out.println("I'm a Simple Program");    }  } 
like image 928
Joseph Avatar asked Nov 30 '10 12:11

Joseph


People also ask

Can you code in Java using notepad?

You can not run java program using notepad. However you can use command prompt if dont intend to use IDE.

Can Notepad++ compile Java?

Go to plugins and open Execute NppExec Script from NppExec . Select Java_Run and click ok to run the Java file in the console; see the output below. The Java program is successfully compiled in Notepad++.


2 Answers

The 'learning curve' associated with IDEs like Eclipse or Netbeans initially mostly involves what you already have above - knowledge of setting class paths, environment variables and so on. Instead of Notepad++ (which I love, but it's not 'made' for Java), I'd recommend Eclipse especially if you have a grunty PC (it's a bit memory hungry). Aside from getting the paths setup, after that you'll be ready to rock.

And Eclipse being actively and openly developed is one of the most documented IDEs out there. The tutorials are bound to work correctly for it :). But seriously, it's pretty good. And then when you want to expand to Android development in Java, or some other type of Java programming, you just load up the add-ins required, and you're away laughing. It also supports debugging, the likes of which Notepad++ certainly cannot compete.

like image 55
Mark Mayo Avatar answered Oct 14 '22 14:10

Mark Mayo


Probably changing the last line to:

java -cp . $(NAME_PART) 

will work for you. The problem is that you aren't setting up the classpath.

Notepad++ will be fine for compiling a single file project. For anything more than this you will need an IDE or at least integrate with ant instead of java compiler.

like image 43
kgiannakakis Avatar answered Oct 14 '22 14:10

kgiannakakis