java - 具有依赖项的 Maven 程序集插件 jar - 插件未运行

标签 java maven jar

我有一个 Maven 项目(父项目的子模块),我需要为其创建一个“具有依赖项的 jar”。我添加了maven-assembly-plugin到 pom.xml,但它没有创建 Artifact 。我慢慢地从 pom.xml 中删除了所有其他内容,直到剩下的只是依赖项和这个插件,但它仍然不会创建带有依赖项的 jar。观察 mvn clean package 的输出它运行 clean , compile ,和jar但从未运行 assembly插入。我不知道为什么。这是 pom.xml,有人能发现问题吗?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>project</groupId>
    <artifactId>project-name</artifactId>
    <version>1.0</version>
    <name>project-name</name>

    <properties>
        <build.time>${maven.build.timestamp}</build.time>
        <spring.framework.version>4.3.1.RELEASE</spring.framework.version>
        <spring.security.version>4.1.1.RELEASE</spring.security.version>
        <spring.webflow.version>2.4.2.RELEASE</spring.webflow.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <sourceDirectory>${project.basedir}/src/java</sourceDirectory>
        <resources>
            <resource>
                <directory>${project.basedir}/src/resources</directory>
            </resource>
        </resources>
        <outputDirectory>${project.basedir}/target/classes</outputDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <dependencies>
        [snip]
    </dependencies>
</project>

最佳答案

Maven reference :

Assemble an application bundle or distribution from an assembly descriptor. This goal is suitable either for binding to the lifecycle or calling directly from the command line (provided all required files are available before the build starts, or are produced by another goal specified before this one on the command line).

asssembly:single 目标可以通过两种方式使用:

  • 通过将其绑定(bind)到生命周期

  • 或者直接从命令行调用

其中任何一个你都没有做到。

例如,您可以将插件执行绑定(bind)到package阶段:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <phase>package</phase> <!-- bind to the packaging phase -->
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
</plugin>

现在,mvn packagemvn install 命令将创建具有依赖项的 jar。

您还可以保留实际的插件配置并运行 mvn assembly:single 命令。

第二种方法允许根据需要创建具有依赖项的 jar,而不是针对每个构建。
如果 jar 创建是一项耗时的任务,不需要在每次构建时执行,那么这可能是理想的。

关于java - 具有依赖项的 Maven 程序集插件 jar - 插件未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43767843/

相关文章:

java - 从输出流中获取输入流

Java ASCII 字符作为字符串输入

java - 尝试替换 editText 字符串开始时出错

java - Maven Surefire : run a single unit test

java - Spring MVC 4.0.0.5、Maven 和 Quartz

java - 将多个项目导出为 jar

java - 从表单调用 servlet 不起作用

java - Eclipse Maven 被阻止

java - 从类路径中动态删除 jar

java - Debian 启停守护进程。 Java启动jar文件