【问题标题】:How to upload the shaded jar after maven build?maven构建后如何上传阴影jar?
【发布时间】:2018-05-03 00:32:59
【问题描述】:

我想通过 SFTP 将包含所有依赖项的已构建 jar 上传到我的 Raspberry Pi。因此我尝试使用 maven-deploy-plugin。

我的配置如下:

<plugin>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8</version>
    <executions>
        <execution>
            <id>Raspberry Pi</id>
            <phase>deploy</phase>
            <goals>
                <goal>deploy-file</goal>
            </goals>
            <configuration>
                <pomFile>pom.xml</pomFile>
                <file>target/${project.name}.jar</file>
                <url>sftp://root@192.168.2.108/home/</url>
            </configuration>
        </execution>
    </executions>
</plugin>

如您所见,上传的 jar 是一个带阴影的 jar,被&lt;finalName&gt;${project.name}&lt;/finalName&gt;重命名

此外,我包含了 wagon-ssh 扩展并定义了 Raspberry Pi:

<extensions>
    <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ssh</artifactId>
        <version>2.8</version>
    </extension>
</extensions>

<distributionManagement>
    <repository>
        <id>Raspberry Pi</id>
        <url>sftp://192.168.2.108/home</url>
    </repository>
</distributionManagement>

但是,如果我执行 mvn:deploy,maven 只会将 original-jar 上传到树莓派到 groupId、artifactId 和 version 的文件路径中。

如何只上传一个没有目录的 jar。

【问题讨论】:

    标签: java maven deployment jar


    【解决方案1】:

    当您使用 Deploy 插件时,Maven 会自动将其部署在以您的工件 groupdId、artifactId 等命名的文件夹中。此行为是内置的,您无法覆盖它,您无能为力。

    但是,您可以使用Wagon plugin 直接通过 SSH 在您的 RPI 上上传,配置如下:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>wagon-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
            <execution>
                <id>upload-raspberry-pi</id>
                <phase>deploy</phase>
                <goals>
                    <goal>upload-single/goal>
                </goals>
                <configuration>
                    <fromFile>target/${project.name}.jar</fromFile>
                    <url>sftp://192.168.2.108/home</url>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    上传将绑定到部署阶段,然后您可以像使用 Deploy 插件一样运行 mvn deploy 以将您的 JAR 上传到您的机器上。

    请注意,如果您使用的是 Maven 3,则必须更新您的项目依赖项。根据Usage 页面:

    此插件不适用于 Maven 3.0.x 和 3.1.x 开箱即用 由于在它的发行版中缺少以下库: commons-io-2.x、common-lang-2.x 和 jsoup-1.x。您可以调用 wagon:update-maven-3 将丢失的文件添加到 $MAVEN_HOME/lib。看 WAGON-407 了解详情

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-26
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 2020-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多