我可以将eclipse源文件夹转换成包吗? [英] Can I convert eclipse source folders into packages?

查看:301
本文介绍了我可以将eclipse源文件夹转换成包吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经分叉了一个Github项目,使用Eclipse在本地进行克隆,并将其作为一般项目导入到Eclipse中。
附带的.project文件是具有适当nature和buildCommandxml标签的Eclipse .project文件。
那么它似乎是一个有效的Eclipse项目。但是,我无法指定运行配置或配置构建路径。
当我选择构建路径弹出菜单项时,它显示为灰色文本中的无可用操作。当我从主菜单中选择Run / Run As时,
显示(不适用)。我想知道问题是项目是否完全导入源文件夹:





没有可以说的包。我从头创建了另一个项目,并根据需要创建了正确的源文件夹和包,
以匹配源代码中的包语句。从git repo手动导入源码后,我可以构建并运行该项目。



如果缺少包确实是问题,Eclipse中是否有快速的方法将源文件夹转换为程序包?

解决方案

您所做的是可能克隆了Eclipse中的repo,然后通过一个新建项目向导,因为在GitHub中没有现有的 .project (而不是)。类路径)文件。



新建项目向导将为一个java项目创建一组缺省值(我怀疑你选择了这个),但是它是对Maven结构的一种注意,所以源文件夹将不被识别,您最终将不得不自己定义它们。更糟糕的是,您将不了解可能在 pom.xml 中配置的Maven构建的任何特殊部分。



因为这个项目使用Maven进行构建,所以在导入它的时候最好使用M2Eclipse。使用帮助 - >安装新软件



然后,需要几个步骤使用所有Eclipse功能。



如果要从头开始,请保留您的克隆的存储库副本或克隆。然后使用 File->导入功能将maven项目导入工作区。选择 Exeiting Maven Projects ,并指向克隆的repo中包含pom.xml文件的目录。这将使用Eclipse中的Maven集成来生成基于 pom的 .project .classpath .xml 内容,所以您将能够更加紧密地模仿Eclipse中的Maven构建。所有源文件夹都应该这样正确发现。 Eclipse可能需要为此特定项目使用的Maven功能安装一些额外的集成。如果是这样的话,可以这样做。



现在,您将使项目在Eclipse中运行和编译,但并不知道它是由Git管理的。 ..这是因为M2Eclipse和Git Team提供者没有集成(至少他们不是上次检查时)。为了能够在Eclipse中提交到存储库,请从工作区中删除项目,但不删除内容。 然后,使用导入项目/导入Exsisting Eclipse项目从Repository视图导入。由于必需的 .project 文件已经生成,Eclipse将自动发现该项目,并将使用M2Eclipse之前准备的正确配置。



最后,您将有一个正确配置的Maven项目,Git作为团队提供者。


I've forked a Github project, used Eclipse to clone it locally, and imported that as a general project into Eclipse. The accompanying .project file is an Eclipse .project file with the proper "nature" and "buildCommand" xml tags. So it seems like a valid Eclipse project. However, I'm unable to specify a run configuration or configure the build path. When I select the Build Path popup menu item, it says "no actions available" in grayed out text. When I select "Run/Run As" from the main menu, it shows (none applicable). I'm wondering if the problem is that the project imported completely as source folders:

There are no packages to speak of. I created another project from scratch, and created the proper source folders and packages as needed to match the package statements in the source code. After manually importing the source from the git repo, I can build and run that project.

If the lack of packages is indeed the problem, is there a quick way in Eclipse to convert source folders to packages?

解决方案

What you did is you have probably cloned the repo in Eclipse and then Imported this project through a New Project Wizard, because in GitHub there is no existing .project (and no .classpath) files.

The "New Project Wizard" will create a set of defaults for a java project (I suspect that you selected just that), but is anaware of Maven structure, so all source folders will not be recognized and you will end up having to define them on your own. Worse, you will be unaware of any special parts of the Maven build that might be configured within pom.xml.

Because this project uses Maven for building, it would be better to use M2Eclipse while importing it. Install it using Help->Install new software.

Then there are a couple of steps required to make it use all Eclipse features.

Keep your cloned copy of the repository or clone again if you want to start from scratch. Then use File->Import feature to import a maven project into the workspace. Select Exisiting Maven Projects and point to the directory containing pom.xml file in the cloned repo. This will use Maven integration in Eclipse to generate .project and .classpath files based on pom.xml contents, so you will be able to more closely mimic Maven build in Eclipse. All source folders should be properly discovered this way. Eclipse might want to install some additional integrations for Maven features that this particular project uses. Let it, if that is the case.

Now, you will have the project operational and compiling in Eclipse, but it will not be aware that it is managed by Git... This is because M2Eclipse and Git Team provider are not integrated (at least they weren't when I last checked). In order to be able to commit to the repository in Eclipse, remove the project from workspace, but without deleting contents. Then, import from Repository view using Import Projects/Import exsisting Eclipse projects. Since necessary .project file is already generated, Eclipse will autodiscover the project and will use the right configuration prepared earlier by M2Eclipse.

In the end you will have a properly configured Maven project with Git as a team provider for it.

这篇关于我可以将eclipse源文件夹转换成包吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆