简体   繁体   English

使用多模块Maven项目,是否可以在Eclipse中使用我的root(pom-packaged)项目?

[英]With multi-module Maven projects, is it possible to make my root (pom-packaged) project available in Eclipse?

We have a fairly large group of Maven2 projects, with a root POM file listing 10+ modules and a lot of properties used by the modules (dependency version numbers, plugin configuration, common dependencies, etc). 我们有一个相当大的Maven2项目组,其中一个根POM文件列出了10多个模块和模块使用的许多属性(依赖版本号,插件配置,公共依赖项等)。 Some of the modules are, like the root project, parents to other sets of modules. 与根项目一样,某些模块是其他模块的父项。

To clarify, the root project and said parent projects are set to pom packaging (as opposed to eg jar). 为了澄清,根项目和所述父项目被设置为pom包装(而不是例如jar)。

Because there are many dependencies between the different projects, I like to use mvn eclipse:eclipse on the root project, which enables me to debug/step into any project at any time. 因为不同项目之间存在许多依赖关系,所以我喜欢在根项目中使用mvn eclipse:eclipse,这使我能够随时调试/步入任何项目。

However, with this approach, the root POM itself, and all other pom-packaged projects, are unavailable in Eclipse. 但是,使用这种方法,根POM本身以及所有其他pom打包的项目在Eclipse中都不可用。 So, if I want to edit them, I have to open them some other way. 所以,如果我想编辑它们,我必须以其他方式打开它们。 This is becoming a bit of a hassle. 这变得有点麻烦。

So, my question is: is it possible to somehow make pom-packaged projects available in Eclipse? 所以,我的问题是:是否有可能以某种方式在Eclipse中提供pom打包的项目? If not, do you have any tips that could make my work with these projects easier? 如果没有,您是否有任何提示可以使我对这些项目的工作更容易?

For the record, I'm currently using MyEclipse 7.0. 为了记录,我目前正在使用MyEclipse 7.0。

I tried this again, with Galileo and the latest version of m2eclipse. 我再试一次,使用Galileo和m2eclipse的最新版本。 It is now possible to import Maven projects directly (without mvn eclipse:eclipse), and it turns out that the root POM is also imported as a project, which is excactly what I wanted. 现在可以直接导入Maven项目(没有mvn eclipse:eclipse),事实证明根POM也作为项目导入,这正是我想要的。

Well. 好。 Lots of people do this by making the parent POM a sibling project, and having a simple reactor POM in the root. 很多人通过使父POM成为兄弟项目,并在根中拥有一个简单的反应器POM来实现这一点。 However this can cause problems with website generation and the release plugin, as neither supports this mode as fully as one might like. 但是,这可能会导致网站生成和发布插件出现问题,因为它们都不像人们所希望的那样完全支持此模式。

A big problem we often have is that people try to check out the trunk using Subclipse, which adds a .project file in the root, which then prevents importing projects below that level. 我们经常遇到的一个大问题是人们试图使用Subclipse检查主干,它在根目录中添加了一个.project文件,然后阻止导入低于该级别的项目。 Instead we have to go outside to check out, then import the projects. 相反,我们必须到外面检查,然后导入项目。

I have heard rumor that Subversive might handle nested projects better, which is really the problem here. 我听说Subversive可能会更好地处理嵌套项目,这真的是问题所在。 Other than that, I don't have an absolute solution here. 除此之外,我在这里没有绝对的解决方案。

Generally I only really need the parent available in eclipse to add dependencies and to avail of the XML formatting. 通常我只需要eclipse中可用的父级来添加依赖项并利用XML格式。 The cheap and cheerful way is to create resources project and link the parent pom into it. 廉价而愉快的方式是创建资源项目并将父pom链接到其中。 File -> New -> Other -> General -> File -> advanced 文件 - >新建 - >其他 - >常规 - >文件 - >高级

if you use the 2.8+ version of the eclipse plugin you can have it generate the link for you in each of your subprojects eg 如果您使用2.8以上版本的eclipse插件,您可以在每个子项目中为您生成链接,例如

<plugin>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.8-SNAPSHOT</version>
    <configuration>
        <linkedResources> 
            <linkedResource>
                <name>parent.xml</name> 
                <type>1</type>
                <location>${basedir}/${parent.relativePath}</location> 
            </linkedResource>
        </linkedResources> 
    </configuration>
  </plugin>

Though you will currently need to check it out from subversion and build it yourself as it doesn't seem to resolve from central yet. 虽然你现在需要从subversion中检查它并自己构建它,因为它似乎无法从中心解析。

svn co http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-eclipse-plugin/
cd maven-eclipse-plugin
mvn clean install

实际上,如果你不想依赖m2eclipse,那么“正确”的方法是使用平面项目布局 (因为问题是Eclipse不支持嵌套项目)。

You could try writing a task to manually create the .project file for each POM project in it's directory. 您可以尝试编写任务以手动为其目录中的每个POM项目创建.project文件。 Not sure on the specifics, but you could generate something like: 不确定具体细节,但你可以生成类似的东西:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>${project.name}</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
        </buildSpec>
        <natures>
        </natures>
</projectDescription>

in the project's root directory and it should be okay. 在项目的根目录中它应该没问题。

I'm not sure whether doing this would then block you from importing the children projects into eclipse though (as you probably know - you need to import all your non-pom projects first and then create "general" projects for the others, with the path matching the physical path under the mvn structure). 我不确定这样做是否会阻止你将子项目导入eclipse(你可能知道 - 你需要先导入所有非pom项目,然后为其他项目创建“一般”项目,路径匹配mvn结构下的物理路径)。 Eclipse will stop you from creating a project inside another, so if it recognises anything from higher in the project hierarchy you'll get headed off at the past. Eclipse将阻止您在另一个项目中创建项目,因此如果它在项目层次结构中从更高层识别出任何内容,那么您将会过去。

I managed to work with codehaus eclipse plugin with maven projects having parents. 我设法使用codehaus eclipse插件与父母的maven项目。 The plugin has some flaws, but overall it is maintained and you should be able to get along with it. 该插件有一些缺陷,但总体来说它是维护的,你应该能够与它相处。

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

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