简体   繁体   English

添加自定义Maven项目作为依赖项

[英]Adding custom maven project as dependency

I'm using eclipse with the m2eclipse plugin now I just want to resolve a - imho - easy problem: I've got two maven projects, I want to add project A as dependency to project B . 我现在使用带有m2eclipse插件的eclipse来解决一个非常简单的问题:我有两个maven项目,我想将project A添加为project B依赖项。

Well how do I achieve this in a manner way? 那么如何以某种方式实现这一目标? If I add the project A to the build path of project B eclipse recognizes the classes but this project isn't resolved by eclipse on build time. 如果我的补充project A来的构建路径project B日食识别类,但这个项目是不是由编译时日食解决。

I got it working by installing project A to my local repo and adding this as dependency to my pom. 通过将project A安装到本地存储库并将其添加为对pom的依赖关系,可以使它正常工作。 This works but is cumbersome because I always have to install a new version of project A when something changed. 这行得通,但是很麻烦,因为更改某些内容后,我总是必须安装新版本的项目A。

Shouldn't the plugin handle such a situation for me? 插件不应该为我处理这种情况吗?

假设您在工作台中都打开了两个maven项目,然后确保在Maven上下文菜单中启用了“启用工作区解析”选项。

The way you did it is correct, because it assumes that project B will be using the dependency of project A that will be in the artifactory, so you can develop both independently. 您这样做的方法是正确的,因为它假定项目B将使用项目A中将存在于项目中的依赖项,因此您可以独立进行开发。

And anyway, for the project A, if you are using maven, don't you use maven clean install for compiling and deploying? 无论如何,对于项目A,如果您使用的是maven,是否不使用maven clean install进行编译和部署? That way you are sure you always have the latest version 这样,您就可以确保始终拥有最新版本

The other option is, in case both of the are more dependent of each other, you should consider make one of them as a module of the other, or maybe make a project C that contains both modules, but that would mean both of them are part of the same project (like an ear containing two jars), depends on the situation 另一个选择是,如果两者之间更加相互依赖,则应考虑将其中一个作为另一个的模块,或者将一个包含两个模块的项目C都考虑在内,但这意味着两个都是同一项目的一部分(例如包含两个罐子的耳朵),取决于情况

Yes Eclipse handle this situations. 是的,Eclipse处理这种情况。

You can add both the Projects A and B in the same work-space. 您可以在同一工作空间中同时添加项目A和项目B。

I could help you creating a simple work-space from the scratch. 我可以帮助您从头开始创建一个简单的工作区。

I am assuming that you have already installed the MAVEN plugin M2Eclipse for Eclipse. 我假设您已经安装了MAVEN插件M2Eclipse for Eclipse。

  1. Start a new Eclipse in a blank Work-space 在空白的工作区中启动新的Eclipse
  2. Right click on Project Explorer --> Go to Import dialog and add a Maven Module. 右键单击Project Explorer->转到Import对话框,然后添加一个Maven模块。
  3. Locate the POM directory and add that directory. 找到POM目录并添加该目录。
  4. It will list all the projects in all the sub folders. 它将列出所有子文件夹中的所有项目。
  5. Add as many as Maven Based modules in a single work-space. 在单个工作空间中添加多达Maven Based模块。

By doing this you dont need to install the dependencies. 这样,您不需要安装依赖项。 Any change will be reflected on the derived module. 任何更改都将反映在派生模块上。

Hope that will help you. 希望对您有所帮助。

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

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