How do I run a single Java file having main() in Eclipse, without creating an entire Java project?

后端 未结 4 1673
夕颜
夕颜 2021-02-13 14:43

Here\'s what I\'ve got:

  1. I have a TestFile.java with the same class name.
  2. This class has a valid main() method.
  3. The file
相关标签:
4条回答
  • 2021-02-13 15:07

    You can't compile & run just one file in Eclipse without the file being in a java project.

    It is a very quick and easy process to create a Java Project in eclipse.

    File -> New -> Java Project
    

    You can use the default package (though it is not recommended) and put your single file in it and run it.

    0 讨论(0)
  • 2021-02-13 15:14

    Try jGRASP, it's a really simple editor and compiler.

    0 讨论(0)
  • 2021-02-13 15:19

    You can run the java file in the cmd command window.

    make sure you have install the java environment.

    java -version
    

    output: java version "1.7.0_07" Java(TM) SE Runtime Environment (build 1.7.0_07-b11) Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

    cd javafilepath
    
    java yourjavafilename.java
    
    0 讨论(0)
  • 2021-02-13 15:22

    You can do that in any Eclipse project with org.eclipse.jdt.core.javanature (check/edit .project file).

    So just open .project file and add

    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
    

    if it is not yet there.

    0 讨论(0)
提交回复
热议问题