Java 和 Maven 构建器如何在 Eclipse 中协同工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6832789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do Java and Maven builders work together in eclipse?
提问by lisak
do I understand correctly, that Java builder recompiles sources on scr path to the output path, which usually happens after each "ctrl + s" if automatic building is activated or via "ctrl + b" or throws validation errors from javac.
我是否理解正确,Java 构建器将 scr 路径上的源重新编译到输出路径,如果自动构建被激活或通过“ctrl + b”或从 javac 抛出验证错误,这通常发生在每个“ctrl + s”之后。
As to Maven2Bulder. I just cloned m2e-core git repository and there is the corresponding class org.eclipse.m2e.core.internal.builder.MavenBuilder, which is quite complicated stuff.
至于Maven2Bulder。我刚刚克隆了 m2e-core git 存储库,并且有相应的类 org.eclipse.m2e.core.internal.builder.MavenBuilder,这是相当复杂的东西。
<projectDescription>
<name>modeshape-example-repositories</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
I thought it gets pom.xml, m2eclipse variables about repo location and settings.xml or some profile information and goal/target of the current Run configuration and it just runs mvn with this pieces of information, but it does much much more and it can produce unexpected behavior.
我认为它获取 pom.xml、关于 repo location 和 settings.xml 的 m2eclipse 变量或当前运行配置的一些配置文件信息和目标/目标,它只是使用这些信息运行 mvn,但它可以做的更多,而且可以产生意想不到的行为。
Btw, is it only used when a developer actually Run As > some maven goal ... ?
顺便说一句,它是否仅在开发人员实际运行时使用 > 某些 maven 目标...?
采纳答案by Ryan Gross
The main purpose of the Maven builder is to ensure the correctness of your POM file and pull down the dependencies that you need. It will go out and check for new dependencies if you save your POM file, and it will report errors when it cannot find dependencies.
Maven 构建器的主要目的是确保您的 POM 文件的正确性并拉下您需要的依赖项。如果你保存你的 POM 文件,它会出去检查新的依赖项,当它找不到依赖项时它会报告错误。
Additionally, the maven builder will run a maven build up to the goal that you have set in Preferences -> Maven->Goal to run after updating project configuration
after you do a Project->Clean...
on your project from eclipse or make changes to the POM file and save it from within eclipse.
此外,maven 构建器将根据您在 eclipse 中对项目进行操作或更改 POM 文件并从 eclipse 中保存Preferences -> Maven->Goal to run after updating project configuration
后设置的目标运行 maven 构建Project->Clean...
。
The Java Builder is still in charge of building the project and reporting compiler errors in the Problems view, for providing the input for the built in jUnit runner in eclipse, etc.
Java Builder 仍然负责构建项目并在 Problems 视图中报告编译器错误,为 eclipse 中内置的 jUnit runner 提供输入等。