无法在从 Git 导入的 Eclipse 中运行项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20207672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:23:50  来源:igfitidea点击:

Can't run project in Eclipse imported from Git

eclipsegitmavengithubegit

提问by emily

I have a project in my Eclipse workspace from Github (via File -> Import -> Projects from GIT). However, I am unable to run the example because the only option I have under "Run As" is "Run Configurations."

我的 Eclipse 工作区中有一个来自 Github 的项目(通过 File -> Import -> Projects from GIT)。但是,我无法运行该示例,因为我在“运行方式”下的唯一选项是“运行配置”。

After going to "Run Configurations" I click "browse" and the project that I imported from GIT isn't there.

转到“运行配置”后,我单击“浏览”,我从 GIT 导入的项目不存在。

Any ideas?

有任何想法吗?

回答by Yiannis Dermitzakis

The question is already answered in the comments but I am providing this answer to possibly clear up some misunderstandings.

这个问题已经在评论中回答了,但我提供这个答案是为了澄清一些误解。

In order to recognize a folder as a (Java) project, Eclipse needs to read (or create) a few files for each project, like .project and .classpath. If you do not have them in your project, or do no create them during the import, then Eclipse just imports it as a resource, or a dumb folder.

为了将文件夹识别为(Java)项目,Eclipse 需要为每个项目读取(或创建)一些文件,如 .project 和 .classpath。如果您的项目中没有它们,或者在导入过程中没有创建它们,那么 Eclipse 只会将其作为资源或哑文件夹导入。

If your project is tracked by git and is also a maven project, you can clone it locally with Git (command line or GUI tool) and then "Import as existing Maven project" in Eclipse. This will use your pom.xml to create the two files mentioned above and your project will be buildable.

如果你的项目被git跟踪并且也是maven项目,你可以用Git(命令行或GUI工具)在本地克隆它,然后在Eclipse中“导入为现有的Maven项目”。这将使用您的 pom.xml 创建上面提到的两个文件,您的项目将是可构建的。

Alternatively, if you have already imported it as you described in your question, you can right click on your project on Package Explorer and choose Configure-->Convert to Maven Project. This will create the .project and allow you to build the project using Maven (right click->Run as..-> Maven build) and Eclipse's incremental builder (where necessary). If your maven project builds an executable, the option to execute it will also be available in the Run as.. menu.

或者,如果您已经按照问题中的描述导入了它,您可以在包资源管理器上右键单击您的项目,然后选择配置--> 转换为 Maven 项目。这将创建 .project 并允许您使用 Maven(右键单击->Run as..-> Maven build)和 Eclipse 的增量构建器(在必要时)构建项目。如果您的 Maven 项目构建了一个可执行文件,则在 Run as.. 菜单中也将提供执行它的选项。

If you have a more complex maven project (like an aggregate pom), and want a Run Configuration that runs a specific program, you will have to write it yourself by opening the Run Configurations window and explicitly referencing the java class.

如果您有一个更复杂的 maven 项目(如聚合 pom),并且想要一个运行特定程序的运行配置,则必须通过打开运行配置窗口并显式引用 java 类来自己编写它。

回答by Pradhuman Singh

Don't import the project using git clone. Download it as zip file and extract it. Add it using Project>import> General> Projectsfrom folder and Archive. Provide path of extracted folder into import source and finish and go to eclipse and clean and build safely run and right click on project and run it. It should work

不要使用git clone. 将其下载为 zip 文件并解压缩。使用Project>import> General> Projects从文件夹和存档添加它。将提取的文件夹的路径提供到导入源并完成并转到eclipse并清理和构建安全运行并右键单击项目并运行它。它应该工作