views:

28

answers:

1

I noticed that when I build even a very simple Java program in Eclipse, and I try to run it from the Terminal/Command Line and it gives me errors. I noticed after some hunting around that I have to actually compile the .java file I created in Eclipse in the Terminal to create and run the application. However, I can just save and run in Eclipse and get the same output (within eclipse).

I checked to see if I could build the project in Eclipse but the option to do so is greyed out. So, how can Eclipse run it if it actually never gets compiled?

+1  A: 

Eclipse does compile it, otherwise it could not run it :-).

Eclipse generates normal .class files, just like javac. It puts them into its "build directory", which you set in the "build path" (or something - Eclipse not handy right now) dialog. By default its under /bin, I believe.

In principle, you can run your program in a terminal using these class files; you just need to set your CLASSPATH accordingly.

In practice, you would either run your program from inside Eclipse (which is for example easier to debug), or deploy your program (using e.g. Ant) to get some kind of installer or installation file, then install that and run it. That way you always run from a complete, correct installation.

Of course for small/simple programs, just running from Eclipse's class files is quite ok.

sleske
I assumed it would, I just wondered why I couldn't run the program from the command line (or in that case I tried it - Terminal) without getting an error. However, after compiling within the terminal I could do it, and just like you suggested, the /bin directory of my project can run just fine, all I have to do is save the changes in Eclipse and the changes showed up in the .class file.
Shawn Strickland