m2eclipse 和 WTP 并添加本地项目源
我在 eclipse 中有一个 spring mvc 项目,其设置为使用 maven。我可以解决所有外部依赖项,但现在我想在工作区中包含另一个本地项目。通常,我会通过 java 构建路径来执行此操作,并添加项目引用。但如果我手动执行此操作,m2eclipse 只会从我的类路径文件中删除这些引用。
我假设这是因为 Maven 想要处理所有依赖项。因此,我在本地项目(我想要包含的源文件)上启用依赖项管理,现在当我添加依赖项时,该项目会显示出来,并将其添加为 jar 类型(这是正确的)。我还运行 maven-package 来创建源项目的快照。但该 jar 从未添加到 Maven 库列表中,并且该项目无法构建,因为它找不到类。
我做错了什么? 感谢您的帮助!
I have a spring mvc project in eclipse, and its setup to use maven. I can resolve all my external dependencies, but now I want to include another local project in my workspace. Normally, I would do this through the java build path, and add a project reference. But if I do that manually, m2eclipse just removes those references from my classpath file.
I'm assuming this is because maven wants to handle all dependencies. So I enable dependency management on the local project (the source files i want to include), and now when I add dependencies, this project shows up, and it adds it as a jar type (which is correct). I also ran maven-package to create a snapshot of the source project. But the jar is never added in the maven library list, and the project doesn't build because it can't find the classes.
What am I doing wrong?
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Eclipse 中 Maven 项目的配置是由 M2Eclipse 从 POM 中包含的元数据派生的,因此如果您有两个项目,
ProjectA
和ProjectB
,并且您希望拥有ProjectB
作为ProjectA
的依赖项,您需要在ProjectA
的 POM 中声明ProjectB
,即添加依赖项:如果您想依赖工作区中的项目(而不是通过本地存储库依赖工件),请在
ProjectA
上右键单击,然后转到属性> Maven 并确保您选择了解决工作区项目的依赖关系,如下所示:替代文本http://img530.imageshack.us/img530/98/screenshot001do.png
The configuration of Maven projects in Eclipse is derived by M2Eclipse from the metadata contained in the POMs so if you have two projects,
ProjectA
andProjectB
, and you want to haveProjectB
as dependency ofProjectA
, you need to declareProjectB
as such in the POM ofProjectA
i.e. to add a dependency:And if you want to depend on the project in the workspace (and not on the artifact through the local repository), right-click on
ProjectA
then go to Properties > Maven and make sure you selected Resolve Dependencies from Workspace projects as illustrated below:alt text http://img530.imageshack.us/img530/98/screenshot001do.png
无法再发表评论,但经过更多阅读后,似乎“解决工作空间依赖关系”仅在这些项目也由 Maven 管理时才有效。如果要添加maven中没有的本地项目怎么办?
can't comment anymore, but after doing some more reading, it seems that the "Resolve Workspace Dependencies" only works if those projects are also managed by Maven. What if you want to add a local project that's not in maven?
您可能需要将本地项目(及其 pom.xml artifactId)添加为 WTP 项目的 pom.xml 中的依赖项,并打开工作区依赖项解析?
You probably need to add the local project (with it's pom.xml artifactId) as a dependency in the pom.xml of the WTP project, and turn on Workspace Dependency resolution?