什么是“正确的”? (暂时)从 Maven 构建中排除源的方法,有没有一种简单的方法可以从 Eclipse 中做到这一点?
我是 Maven 新手,而且我也没有太多 Eclipse 经验。
为了从 Eclipse 中的构建中排除 java 文件,我右键单击这些文件并选择“构建路径”->“构建路径”。排除。这对于 Eclipse 中的“保存时”编译非常有效,但它不会传播到 Maven 项目,因此当我使用 mvn install 构建项目时,它会尝试编译排除的源。
我做了一些搜索,结果将我指向编译器插件和
(暂时)从 Maven 构建中排除源的“正确”方法是什么?是否有一种简单的方法可以通过 m2eclipse 插件或其他方式从 Eclipse 执行此操作?
I'm new to maven, and I don't have a whole lot of experience with Eclipse either.
To exclude java files from building in Eclipse, I right click the files and choose Build Path -> Exclude. This works great for the "on-save" compilation in Eclipse, but it does not propagate to the maven project, so when I build my project with mvn install, it tries to compile the excluded sources.
I've done a few searches and the results point me to the compiler plugin and the <excludes> functionality, but editing maven project files in order to temporarily exclude a file from the build seems a bit awkward.
What's the "right" way to (temporarily) exclude sources from a maven build, and is there an easy way to do it from Eclipse, via the m2eclipse plugin or otherwise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 <排除> Maven 编译器插件中的参数可暂时从编译中排除文件。
如果您使用 M2Eclipse 插件并运行 Maven->Update Project Configuration,pom 中排除的文件也应该自动从 eclipse 编译中排除。
You could use the <excludes> parameter in Maven Compiler plugin to temporarily exclude files from compilation.
If you are using M2Eclipse plugin and run Maven->Update Project Configuration, the excluded files in the pom should automagically get excluded from eclipse compilation as well.
如果你选择maven作为项目管理,那么你真的必须按照“maven方式”来做。
Eclipse根据项目属性中指定的类路径构建项目,它与maven编译器插件的类路径无关。 “mvncompile”仅由编译器插件的配置驱动。
通常,这些“临时”更改由附加到 Maven 目标(从 cmd 运行的 Maven 插件/Mojo 目标)的 JVM 参数来处理,您创建(自定义)并保存在“运行为”> 中。 “运行配置”。我对 Maven 使用命令行(shell)而不是 m2eclipse。更改参数对我来说更快。
要了解可以使用哪些参数,您可以在 Maven 依赖项中指定特定的 Mojo(maven 插件)(只是暂时的)并在 Eclipse 中查看其源代码,您可以看到可以通过“-D”指定的参数JVM 参数。或者您可以查看文档。
在编译器插件中有一个参数
private Set; excepts = new HashSet();
但不幸的是集合参数不能指定为 JVM 参数...所以剩下的唯一选择是在 pom.xml 中配置插件声明。然后还有配置文件,但它们对于这种情况没有用处。
总而言之,您的需求相当罕见,从编译中排除 java 类并不是通常的需求。
我希望它有帮助
if you choose maven as project management, then you really have to do it the "maven way".
Eclipse builds the project based on the classpath specified in project properties and it doesn't relate to classpath of maven compiler plugin. "mvn compile" is driven only by configuration of compiler plugin.
Usually these "temporary" changes are dealt with by JVM parameters appended to the maven goal (maven plugin/Mojo goal that you are running from cmd), that you create (custom one) and save in "Run as" > "Run configurations". I use commandline (shell) rather than m2eclipse for maven. changing parameters is quicker for me.
To find out what parameters you can use, you can either specify the particular Mojo (maven plugin) in you maven dependencies (just temporarily) and look at its sources right in eclipse, you can see parameters that can be specified via "-D" JVM parameters. Or you can check the documentation.
In compiler plugin there is a parameter
private Set<String> excludes = new HashSet<String>();
but unfortunately collection parameters cannot be specified as JVM parameters... So the only option left is configure the plugin declaration in pom.xml.Then there are also profiles, but they are not useful for this case.
To summarize it, your requirement is rather rare, excluding a java class from compilation is not a usual requirement.
I hope it helps