Maven在eclipse中使用m2Eclipse查询

发布于 2024-09-13 12:04:51 字数 244 浏览 5 评论 0原文

我在 Eclipse 中使用 Maven 和 m2Eclipse 插件。

我对如何在 Eclipse 中构建它感到非常困惑。

即时编译正常工作(即就像没有 Maven 一样),因此如果出现错误,它将突出显示。

但是,例如,当我想运行 junit 时,只有在运行 Maven 构建命令后才会拾取对代码的任何更改。 Eclipse 项目 clean 似乎不起作用。

任何帮助解释这一切应该如何工作的帮助将不胜感激。

I'm using Maven in Eclipse with the m2Eclipse plugin.

I'm very confused about how this is supposed to build within eclipse.

The on-the-fly compiling works as normal (i.e. as if without maven) so if you have an error it will be highlighted.

But when I want to run a junit for example, any changes to the code are only picked up after I run a maven build command. The Eclipse project clean doesn't seem to work.

Any help in explaining how this is all supposed to work would be greatly appreciated.

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

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

发布评论

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

评论(2

羅雙樹 2024-09-20 12:04:52

eclipse 构建器使用比 maven 更简单的逻辑,因此有时 m2eclipse 所做的事情还不够。在运行单元测试之前,我通常保持 shell 打开以发出简单的命令。根据您的设置,这里有一些可能有用的命令。

mvn process-resources
# This is usually enough when you have
# changed something in src/main/resources

如果您知道唯一需要的资源处理是maven资源过滤,只需调用目标:

mvn resources:resources

测试相同:

mvn processs-test-resources

或者

mvn resources:test-resources

如果您需要更完整的解决方案,因为可能需要生成一些新代码等,那么使用

mvn test-compile
# This will through recursion process the following phases:

validate
initialize
generate-sources
process-sources
generate-resources
process-resources
compile
process-classes
generate-test-sources
process-test-sources
generate-test-resources
process-test-resources
test-compile

所以您会变得漂亮除了实际的单元测试执行之外的一切。大多数插件都足够智能,可以检测更改并保留未更改的文件,因此 mvn test-compile 通常足够快。

如果您不想使用 shell,您当然可以将上述任何阶段/目标绑定到 m2eclipse Run as... maven build 目标。

The eclipse builder uses simpler logic than maven, so sometimes the things m2eclipse does are just not enough. I usually keep a shell open to issue simple commands before I run unit tests. depending on your setup, here are some commands that might be helpful.

mvn process-resources
# This is usually enough when you have
# changed something in src/main/resources

If you know that the only resource processing needed is maven resource filtering, just call the goal:

mvn resources:resources

Same for tests:

mvn processs-test-resources

or

mvn resources:test-resources

If you need a fuller solution, because perhaps some new code has to be generated etc, then use

mvn test-compile
# This will through recursion process the following phases:

validate
initialize
generate-sources
process-sources
generate-resources
process-resources
compile
process-classes
generate-test-sources
process-test-sources
generate-test-resources
process-test-resources
test-compile

So you're getting pretty much everything except the actual unit test execution. Most plugins are smart enough to detect changes and leave unchanged files alone, so mvn test-compile is usually fast enough.

If you prefer not to use a shell, you can of course bind any of the above phases / goals to m2eclipse Run as... maven build targets.

帅哥哥的热头脑 2024-09-20 12:04:52

查看 http://m2eclipse.sonatype.org/ 插件文档和指南。

Checkout the http://m2eclipse.sonatype.org/ plugin documentation and guide.

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