简体   繁体   English

在Eclipse中运行Java程序

[英]running java programs in Eclipse

I am having a problem running java programs in Eclipse, 我在Eclipse中运行Java程序时遇到问题,

When i Click on Run button to Run the Project i get error until i manually Add that project in Run Configurations , Why do i have to add Evey project in Run configurations before running it ? 当我单击“运行”按钮运行项目时,出现错误,直到在“运行配置”中手动添加该项目时,为什么在运行该项目之前必须在“运行配置”中添加Evey项目? If i have a single .java file i couldn't be able to run this file as i cannot add this File in Run Configurations because it is just a single file not a complete project having a package. 如果我只有一个.java文件,那么我将无法运行该文件,因为我无法在“运行配置”中添加此文件,因为它只是一个文件,而不是具有软件包的完整项目。

Last time when i was using eclipse and whenever i click on Run the project i selected automatically runs without adding it inside the Run configurations but since i Deleted and Eclipse and Re-Install it i am facing these kind of troubles , could somebody help me out ? 上次使用eclipse时,每当我单击“运行”项目时,我选择的项目都会自动运行,而不会在“运行”配置中添加它,但是由于我删除了它并进行了Eclipse并重新安装,因此我遇到了此类麻烦,有人可以帮助我?

右键单击您的主类>运行方式...> Java应用程序

Right-click on the java class you want to run and select Run as > Java application 右键单击要运行的Java类,然后选择Run as > Java application

Your class must have a method with this signature: 您的类必须具有带有此签名的方法:

public static void main(String[] args) 

There's a configuration for what the run button does. 运行按钮有一个配置。 it will either try to relaunch whatever was launched previously, or will try to launch the currently open document, which could be an xml file too... look into window->preferences and search for "run" or "launch" 它将尝试重新启动之前启动的任何文件,或者尝试启动当前打开的文档(也可能是xml文件)...查看window-> preferences并搜索“ run”或“ launch”

If its a single java file then you can right click on the file and select the "run as java application" option to allow you to run the program. 如果它是单个Java文件,则可以右键单击该文件,然后选择“以Java身份运行”应用程序选项,以允许您运行该程序。

The Run Configurations option is used to make sure that you save some project specific run setings and use that shortcut each time to run the project. “运行配置”选项用于确保您保存一些项目特定的运行设置,并在每次运行项目时都使用该快捷方式。

For single programs i think the first option is better. 对于单个程序,我认为第一个选择更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM