m2eclipse 和 WTP 并添加本地项目源

发布于 2024-08-27 07:18:13 字数 353 浏览 13 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

像你 2024-09-03 07:18:13

Eclipse 中 Maven 项目的配置是由 M2Eclipse 从 POM 中包含的元数据派生的,因此如果您有两个项目,ProjectAProjectB,并且您希望拥有 ProjectB 作为 ProjectA 的依赖项,您需要在 ProjectA 的 POM 中声明 ProjectB ,即添加依赖项:

<dependency>
  <groupId>group.id.of.b</groupId>
  <artifactId>project-b</artifactId>
  <version>1.2.3-SNAPSHOT</version>
</dependency>

如果您想依赖工作区中的项目(而不是通过本地存储库依赖工件),请在 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 and ProjectB, and you want to have ProjectB as dependency of ProjectA, you need to declare ProjectB as such in the POM of ProjectA i.e. to add a dependency:

<dependency>
  <groupId>group.id.of.b</groupId>
  <artifactId>project-b</artifactId>
  <version>1.2.3-SNAPSHOT</version>
</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

寂寞花火° 2024-09-03 07:18:13

无法再发表评论,但经过更多阅读后,似乎“解决工作空间依赖关系”仅在这些项目也由 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?

舞袖。长 2024-09-03 07:18:13

您可能需要将本地项目(及其 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文