简体   繁体   English

Maven/Eclipse 插件:让新 Maven 项目依赖于旧的非 Maven 项目的最简单方法?

[英]Maven/Eclipse plugin: easiest way to have new Maven project have dependency on legacy non-Maven project?

I created a new Maven project in Eclipse.我在 Eclipse 中创建了一个新的 Maven 项目。 This was working fine until I needed to add a dependency to another Eclipse project, a legacy utility project, which does not have a pom.xml, and does not have the directory structure of a typical Maven project.这一直很好,直到我需要向另一个 Eclipse 项目添加依赖项,这是一个遗留实用程序项目,它没有 pom.xml,也没有典型 Maven 项目的目录结构。 (It has the directory structure of a typical eclipse Java project). (它具有典型 eclipse Java 项目的目录结构)。 This other project is in the same Eclipse workspace as the Maven project.另一个项目与 Maven 项目位于同一个 Eclipse 工作区中。

In looking at other posts on this, it seems that usually the solution is to build the jar for the other project and install it in Maven.在查看有关此的其他帖子时,似乎通常的解决方案是为其他项目构建 jar 并将其安装在 Maven 中。 However I am actively modifying code in the utility project while writing code in the Maven project, so I can't just install a jar once to satisfy the dependency.然而我在Maven项目中编写代码的同时,我正在积极修改utility项目中的代码,所以我不能只安装一次jar来满足依赖关系。

What is the easiest way to handle this so that I can code simultaneously in both projects, and also get maven to build cleanly?处理这个问题的最简单方法是什么,以便我可以在两个项目中同时编码,并且还可以让 Maven 干净地构建? (Of course Eclipse can build just fine with just a project dependency.) (当然 Eclipse 可以只用一个项目依赖就可以很好地构建。)

UPDATE更新

Using the Build Helper plugin to add the utility projects source folder to my pom was a viable path to the solution, but then I needed to update all the dependencies of the utility project into my new Mavne project, which started to make the whole process too time consuming (and also not really the chain of dependencies I wanted).使用 Build Helper 插件将实用程序项目源文件夹添加到我的 pom 是解决方案的可行路径,但随后我需要将实用程序项目的所有依赖项更新到我的新 Mavne 项目中,这也开始制作整个过程耗时(而且也不是我真正想要的依赖链)。 I think that if I would have added all the dependencies, then Build Helper suggestion would have worked.我认为如果我添加了所有依赖项,那么 Build Helper 建议就会起作用。

For now, I built the utility project jar and installed it into maven.现在,我构建了实用程序项目 jar 并将其安装到 maven 中。 Which turned out to be the the quickest solution.结果证明这是最快的解决方案。 I will try to Mavenize the utility project, without modifying its structure (as suggested by FrVaBe below), and see if I can link the poms afterward.我将尝试 Mavenize 实用程序项目,而不修改其结构(如下面的 FrVaBe 所建议的),然后看看我是否可以链接 poms。

I am going to keep this question open until I have a full solution which can be reported back, since I assume this is a problem others will have (trying to integrate legacy projects with new maven projects).我将保持这个问题开放,直到我有一个完整的解决方案可以报告回来,因为我认为这是其他人会遇到的问题(尝试将遗留项目与新的 maven 项目集成)。

For the development time you can add the dependency as a System Dependency . 对于开发时间,您可以将依赖项添加为系统依赖项 It will be resolved by the file path (which can be the path to your utility.jar file under development) in this case. 在这种情况下,它将由文件路径(可以是正在开发的Utility.jar文件的路径)解析。

It is added as describe in the link above, eg: 它是按上面链接中的描述添加的,例如:

  <dependencies>
    <dependency>
      <groupId>my-utility</groupId>
      <artifactId>my-utility</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>${somewhere}/lib/my-utility.jar</systemPath>
    </dependency>
  </dependencies>

The maven handling of System dependencies is sometimes special. 系统依赖项的Maven处理有时很特殊。 Eg they will not be included in war-packages! 例如,它们将不会包含在战争包装中! Therefore, when you are finished I would strongly recommend to install your utility library to the maven respository or to deploy it to a repository manager (Nexus/Artifactory). 因此,完成后,我强烈建议您将实用程序库安装到Maven存储库中,或将其部署到存储库管理器(Nexus / Artifactory)。

You can add utility project's src folder to your working project in eclipse. 您可以在Eclipse中将实用程序项目的src文件夹添加到您的工作项目中。 For your development purpose. 为了您的发展目的。

right click on Working project
go to properties and choose java build path
go to source tab
Add your utility project src folder to that.

Later you can install your jar as maven dependency. 稍后,您可以将jar安装为maven依赖项。

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

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