将 Eclipse 用于 Intellij Idea 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1075538/
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 13:50:51  来源:igfitidea点击:

Using Eclipse for Intellij Idea projects

eclipseintellij-ideaproject-structure

提问by Alberto Zaccagni

I like Eclipse and I want to use it, the problem is that I can't figure out a simple and fast way to configure projects once checked out from svn.

我喜欢 Eclipse 并且我想使用它,问题是一旦从 svn 签出,我就想不出一种简单快速的方法来配置项目。

All projects I work with have several modules and are configured with a top folder which contains four folders: the build output, libs, main and profiles.

我使用的所有项目都有几个模块,并配置了一个顶层文件夹,其中包含四个文件夹:构建输出、libs、main 和配置文件。

In detail:

详细:

  • libs contains compile libs, test libs and normal usage libs.
  • main contains three folders: java (for sources), resources (for things like ibatis xml) and webcontent (for jsps, css, js, imgs and the like)
  • profiles contains three folders: personal, test and production which are added to the build depending on the target environment.
  • libs 包含编译库、测试库和正常使用库。
  • main 包含三个文件夹:java(用于源代码)、资源(用于 ibatis xml 之类的东西)和 webcontent(用于 jsps、css、js、imgs 等)
  • 配置文件包含三个文件夹:个人、测试和生产,它们根据目标环境添加到构建中。

How can I achieve this using Eclipse? This is the only thing I dislike of this ide, I've always found difficult to configure a project the way I want (and not the way it wants :P)

如何使用 Eclipse 实现这一目标?这是我唯一不喜欢这个ide的地方,我总是发现很难按照我想要的方式配置项目(而不是它想要的方式:P)

I was always told that Eclipse uses a very strict structure for its projects, but I can't believe there is no solution and I just have to stick with Idea. I want to work with something I like, I think this is fundamental.

我总是被告知 Eclipse 对其项目使用非常严格的结构,但我不敢相信没有解决方案,我只能坚持使用 Idea。我想用我喜欢的东西工作,我认为这是最基本的。

Also, do you think this is a good configuration for a project? What if I just change it to my needs with a script that rearranges the structure after svn checkout? Will I have problems when committing files to svn this way? I don't want to change everyone's structure on svn.

另外,你认为这是一个很好的项目配置吗?如果我只是使用在 svn checkout 后重新排列结构的脚本将其更改为我的需要怎么办?以这种方式将文件提交到 svn 时我会遇到问题吗?我不想改变每个人在 svn 上的结构。

采纳答案by Csaba_H

There are definitely come constraints in an Eclipse workspace but it is quite flexible (with linked folder and include/exclude support). There are some detailed examples in the project configuration tutorial.

Eclipse 工作区中肯定存在约束,但它非常灵活(具有链接文件夹和包含/排除支持)。项目配置教程中有一些详细的例子。

If I understand the layout correctly I think you do not have to change this structure (at least for the sources). You can create a bunch of java projects and/or dynamic web projects (latter for web "modules"), one per module (you should treat an Idea project as an Eclipse workspace and a module as an Eclipse project). You can set webcontent as the content directory, main/java and main/resources as java source folders and you can add the jars from libs to the build path (or simply put them in the webcontent/WEB-INF/lib directory).

如果我正确理解布局,我认为您不必更改此结构(至少对于源代码)。您可以创建一堆 Java 项目和/或动态 Web 项目(后者用于 Web“模块”),每个模块一个(您应该将 Idea 项目视为 Eclipse 工作区,将模块视为 Eclipse 项目)。您可以将 webcontent 设置为内容目录,将 main/java 和 main/resources 设置为 java 源文件夹,并且您可以将 libs 中的 jar 添加到构建路径中(或者简单地将它们放在 webcontent/WEB-INF/lib 目录中)。

The most complicated stuff is the profiles and the compile/test/normal libraries. I would put the normal and compile libs to the build path of the project and add the test libs explicitly to the classpath of a test run configuration. For the profile I do not know a simple method - maybe a fourth linked folder which always map the one actually used...

最复杂的东西是配置文件和编译/测试/普通库。我会将普通库和编译库放在项目的构建路径中,并将测试库显式添加到测试运行配置的类路径中。对于配置文件,我不知道一个简单的方法 - 也许是第四个链接文件夹,它总是映射实际使用的文件夹......

The Idea migration faqcan also help to summarize some key differences between the two ide.

理念迁移常见问题还可以帮助总结两个IDE之间的一些关键区别。

回答by Roland Schneider

If understand you correctly you can "import" the project by creating a new one.

如果理解正确,您可以通过创建一个新项目来“导入”项目。

  1. File -> New -> Java Project
  2. Select "Create Project from existing source" and Browse to your project-directory
  3. Click next in order to see if Eclipse has got it the way you want it
  1. 文件 -> 新建 -> Java 项目
  2. 选择“从现有源创建项目”并浏览到您的项目目录
  3. 单击下一步以查看 Eclipse 是否按您希望的方式得到它

Usually Eclipse does a nice job on detecting you project layout, so this should do this. Additionally, like Csaba_H said, you might have to adapt the project for the testing stuff.

通常 Eclipse 在检测您的项目布局方面做得很好,所以应该这样做。此外,就像 Csaba_H 所说的那样,您可能必须针对测试内容调整项目。

Another solution would be migrating this project to a build system like Apache Maven 2(I know that it is a project management tool ;)). All modern IDE's (Eclipse only with 3rd party plug-ins M2Eclipseor Q for Eclipse) support importing Maven projects directly so you do not have to adapt anything. Additional Maven has a dependency management which takes care of download dependencies, adding them to the correct classpath, depending on the scope (compile, test, runtime). Maven usually follows the "Convention over configuration"-rules and so it defines a standard path for your java/test classes/resources, but you can configure them to your layout if you want to. If you chose to give it a try you should check out the free book Maven: The Definitive Guide

另一种解决方案是将这个项目迁移到像Apache Maven 2这样的构建系统(我知道它是一个项目管理工具;))。所有现代 IDE(Eclipse 仅带有第 3 方插件M2EclipseQ for Eclipse)都支持直接导入 Maven 项目,因此您无需调整任何内容。额外的 Maven 有一个依赖管理,它负责下载依赖,根据范围(编译、测试、运行时)将它们添加到正确的类路径中。Maven 通常遵循“约定优于配置”规则,因此它为您的 java/test 类/资源定义了标准路径,但您可以根据需要将它们配置到您的布局中。如果您选择尝试一下,您应该查看免费书籍Maven:权威指南