views:

407

answers:

4

In the past, I have used JCreator to develop my java applications. I wanted to try Eclipse and see its IDE.

On JCreator, I could just open a java file and run it in the command prompt. On Eclipse, I cannot find out how I can compile and run a java file written by someone else without first creating a project, creating a new java class and then copy and pasting the code from the file.

I cannot even figure out how to import a java file into the project.

So my questions:
1. How can I open, compile and run a java file without first creating a java project.
2. How can I import a java file into a project I already have.
3. How can I run the program in command prompt, instead of on the console that is in Eclipse, (update: to be more clear) directly from the Eclipse.

Thank you.

A: 

2) Use the "Import" command. Ensure the java file goes to the "src" directory.

3) One way is to export your classes to a JAR file and then run the JAR file at the command prompt (e.g. java -jar file.jar)

nzpcmad
+1  A: 
  1. As far as I know, you can't
  2. Right click project > Import
  3. With respect to your platform, something roughly equivalent to: java <classname>. (Make sure java is in your path, otherwise use the absolute path to the it.)
Aram Verstegen
+2  A: 
VonC
+1  A: 

A useful feature is available in Eclipse since version 3.4: you can paste the text of a Java class into a Java project (copy the content of the class, select the project or source folder, paste). This will create an appropriately named file, in the correct package. This is probably the easiest way to import a single class.

Fabian Steeg