有没有如何使用 maven-jar-plugin 的示例?
我对 Maven 很陌生,希望看到一个如何使用 Maven jar 插件的示例。我已经访问过 此处 但没有找到任何示例。在文档页面上,为此目标列出了一些参数,但我正在寻找的是如何将它们放置在“目标”或“执行”标签中。谢谢。
I am very new to Maven and would like to see an example of how one uses the maven jar plugin. I already visited here but did not find any examples. On the documentation page, there were some parameters listed for this goal but what I was looking for is how one places them in the 'goal' or 'executions' tag. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您通常不使用 jar 插件。如果将打包设置为 jar,则目标 jar:jar 会自动执行。
如果要配置 jar 插件,请像这样进行:(
示例:从 jar 中排除所有 xml 文件)
无需添加任何目标或执行块,全局配置块对所有执行都有效。
参考:
You usually don't use the jar plugin. If you set the packaging to jar, the goal jar:jar gets executed automatically.
If you want to configure the jar plugin, do it like this:
(Example: exclude all xml files from the jar)
There is no need to add any goal or execution blocks, a global configuration block is valid for all executions.
Reference:
所有 Maven 插件通常都有一个 Usage 页面, Maven JAR 插件。但正如 seanizer 所指出的,直接调用 Maven JAR 插件是不寻常的,你并没有真正“直接使用它”,Maven 确实如此。
Maven 附带了由阶段 (例如
compile
、test
、package
等)和 默认生命周期绑定(绑定到阶段的插件目标)取决于项目的打包。作为用户,您调用阶段
(例如package
),然后Maven 使用特定的插件目标来实际完成这项工作。例如,对于具有
jar
类型的packaging
的项目,绑定到package
的目标是jar:jar
Maven 会将您的项目打包为 JAR。对于packaging
类型为war
的项目,war:war
绑定到package
并且 Maven 会生成一个打包
期间发生 WAR。等等。这种方法的好处是,无论项目类型如何(
jar
、war
、ear
等),您都不需要知道构建它的细节。您只需要知道“已知”阶段:compile
将编译项目,test
将编译并运行测试,package
将打包它,等等。配置插件指南解释了配置规则任何 Maven 插件,通过指定
元素来完成。此
可以是通用的(全局),也可以特定于参与 构建生命周期。一旦您知道如何配置其中一个,您就可以配置其中任何一个(只有参数特定于每个插件)。在 Maven JAR 插件的特定情况下,全局
就足够了,您不太可能需要特殊的
(除了默认一个)。All maven plugins have usually a Usage page, so does the Maven JAR Plugin. But as pointed out by seanizer, it's unusual to invoke the Maven JAR Plugin directly, you don't really "use it directly", Maven does.
Maven comes with a build lifecycle made of phases (e.g.
compile
,test
,package
, etc) and default Lifecycle Bindings (plugins goals bound to phases) which depend on the packaging of your project. And as user, you invoke aphase
(e.g.package
) and Maven then uses specific plugin goals to actually do the job.For example, for a project with a
packaging
of typejar
, the goal bound topackage
isjar:jar
and Maven will package your project as JAR. For a project with apackaging
of typewar
,war:war
is bound topackage
and Maven would produce a WAR duringpackage
. And so on.The benefit of this approach is that regardless of the project type (
jar
,war
,ear
, etc), you don't need to know the details to build it. You just need to know "known" phases :compile
will compile a project,test
will compile and run tests,package
will package it, etc.The Guide to Configuring Plug-ins explains the rules to configure any Maven plugin, which is done by specifying a
<configuration>
element. This<configuration>
can be either generic (global) or specific to an<execution>
for goals that participate to a particular phase of the build lifecycle. And once you know how to configure one of them, you can configure any of them (only the parameters are specific to each plugin).In the particular case of the Maven JAR Plugin, a global
<configuration>
should suffice, it's unlikely that you'll need a special<execution>
(additional to the default one).