m2eclipse:Maven 依赖项作为 JAR 而非项目

发布于 2024-08-21 12:26:19 字数 455 浏览 1 评论 0原文

我正在 Eclipse 上使用 m2eclipse 插件创建 Maven 项目。该项目有一些依赖项。其中一些是 slf4j、apache-commons 等库。但也有我的库,我正在 eclipse 中同时开发。不幸的是,m2eclipse 创建构建路径的方式是,我的库不是作为来自 M2 存储库的 JAR 存档,而是作为来自 /target/classes 目录的类文件添加到类路径中。因此,我无法使用 maven-shade-plugin,因为我收到一条消息:

创建着色 jar 时出错:打开 zip 文件 /home/user/workspace/my-project/project-a/target 时出错/类”。

当我使用 mvn clean install 从命令行构建 project-a 时,一切正常 - 生成了阴影 JAR。如何修复它?

I'm having maven project on Eclipse with m2eclipse plugin. This project has some dependencies. Some of them are libraries as slf4j, apache-commons etc. But there are also mine libraries, that I'm developing simultaneously in eclipse. Unfortunately m2eclipse creates build path in such a way that my libraries are added to the classpath not as a JAR archives from M2 repository but as class files from /target/classes directory. For that reason I can not use maven-shade-plugin beacuse I'm gettin a message:

" Error creating shaded jar: error in opening zip file /home/user/workspace/my-project/project-a/target/classes".

When I'm building project-a from command line using mvn clean install everything works well - shaded JAR is generated. How to fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

三月梨花 2024-08-28 12:26:19

经过几个小时的搜索,我已经找到了解决方案。这可以通过配置 Maven 构建配置来完成
1. 选择“运行为...”按钮上的箭头
2. 选择运行配置...
3.选择你的项目Maven Builder
4. 在右侧选项卡(主选项卡)上取消选择:解决工作区工件。

单击“应用”并构建您的项目 - 一切都会如您所愿:)。

After few hours of searching I've already found solution. This can be made by configurinng Maven Build Configuration
1. Select arrow on Run as.. button
2. Select Run configurations...
3. Select yours project Maven Builder
4. On the right tab (Main tab) deselect: Resolve Workspace artifacts.

Click Apply and build your project - all will work as you wish :).

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