有没有如何使用 maven-jar-plugin 的示例?

发布于 2024-09-29 13:52:46 字数 212 浏览 5 评论 0原文

我对 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 技术交流群。

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

发布评论

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

评论(2

半衬遮猫 2024-10-06 13:52:46

您通常不使用 jar 插件。如果将打包设置为 jar,则目标 jar:jar 会自动执行。

如果要配置 jar 插件,请像这样进行:(

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <configuration>
        <excludes>
            <exclude>**/*.xml</exclude>
        </excludes>
    </configuration>
</plugin>

示例:从 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:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <configuration>
        <excludes>
            <exclude>**/*.xml</exclude>
        </excludes>
    </configuration>
</plugin>

(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:

相权↑美人 2024-10-06 13:52:46

我对 Maven 很陌生,希望看到一个如何使用 Maven jar 插件的示例。我已经访问过这里,但没有找到任何示例。

所有 Maven 插件通常都有一个 Usage 页面, Maven JAR 插件。但正如 seanizer 所指出的,直接调用 Maven JAR 插件是不寻常的,你并没有真正“直接使用它”,Maven 确实如此。

Maven 附带了由阶段 (例如 compiletestpackage 等)和 默认生命周期绑定(绑定到阶段的插件目标)取决于项目的打包。作为用户,您调用阶段(例如package),然后Maven 使用特定的插件目标来实际完成这项工作。

例如,对于具有 jar 类型的 packaging 的项目,绑定到 package 的目标是 jar:jar Maven 会将您的项目打包为 JAR。对于 packaging 类型为 war 的项目,war:war 绑定到 package 并且 Maven 会生成一个打包期间发生 WAR。等等。

这种方法的好处是,无论项目类型如何(jarwarear 等),您都不需要知道构建它的细节。您只需要知道“已知”阶段:compile将编译项目,test将编译并运行测试,package将打包它,等等。

在文档页面上,为此目标列出了一些参数,但我正在寻找的是如何将它们放置在“目标”或“执行”标签中。

配置插件指南解释了配置规则任何 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.

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 a phase (e.g. package) and Maven then uses specific plugin goals to actually do the job.

For example, for a project with a packaging of type jar, the goal bound to package is jar:jar and Maven will package your project as JAR. For a project with a packaging of type war, war:war is bound to package and Maven would produce a WAR during package. 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.

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.

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).

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