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

不问归期 提交于 2019-12-03 10:54:11

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.

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

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!