添加自定义 Maven 项目作为依赖项
我现在正在将 Eclipse 与 m2eclipse 插件一起使用,我只想解决一个 - 恕我直言 - 简单的问题:我有两个 Maven 项目,我想将 project A
添加为 project 的依赖项B。
那么我该如何以某种方式实现这一目标呢?如果我将 project A
添加到 project B
的构建路径中,Eclipse 会识别这些类,但 Eclipse 在构建时不会解析该项目。
我通过将 project A
安装到我的本地存储库并将其作为依赖项添加到我的 pom.xml 来使其正常工作。这可行,但很麻烦,因为当事情发生变化时我总是必须安装项目 A 的新版本。
插件不应该为我处理这种情况吗?
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
.
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.
I got it working by installing project A
to my local repo and adding this as dependency to my pom. This works but is cumbersome because I always have to install a new version of project A when something changed.
Shouldn't the plugin handle such a situation for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在工作台中打开了两个 Maven 项目,请确保在 Maven 上下文菜单中启用了“启用工作空间解析”选项。
Providing that you have both maven projects open in your workbench then make sure you have the "Enable Workspace Resolution" option enabled in the Maven context menu.
是的,Eclipse 可以处理这种情况。
您可以将项目 A 和 B 添加到同一工作空间中。
我可以帮助您从头开始创建一个简单的工作空间。
我假设您已经为 Eclipse 安装了 MAVEN 插件 M2Eclipse。
通过这样做,您不需要安装依赖项。任何更改都将反映在派生模块上。
希望这会对您有所帮助。
Yes Eclipse handle this situations.
You can add both the Projects A and B in the same work-space.
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.
By doing this you dont need to install the dependencies. Any change will be reflected on the derived module.
Hope that will help you.
您的做法是正确的,因为它假设项目 B 将使用项目 A 的依赖项,该依赖项将位于工件中,因此您可以独立开发两者。
而且不管怎么说,对于项目A来说,如果你使用的是maven,那你不是用maven clean install来编译部署吗?这样你就可以确保你始终拥有最新版本
另一种选择是,如果两者更加相互依赖,你应该考虑将其中一个作为另一个的模块,或者创建一个包含以下内容的项目 C两个模块,但这意味着它们都是同一个项目的一部分(就像一个耳朵包含两个罐子),取决于具体情况
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.
And anyway, for the project A, if you are using maven, don't you use maven clean install for compiling and deploying? 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