1
votes

I would like to upload the builded jar with all dependencies via SFTP to my Raspberry Pi. Therefore I tried to use maven-deploy-plugin.

My configuration looks like:

<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://[email protected]/home/</url>
            </configuration>
        </execution>
    </executions>
</plugin>

As you can already see, the uploaded jar is a shaded jar which is renamed by <finalName>${project.name}</finalName>

Furthermore I included the wagon-ssh extension and defined the 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>

However, if I execute mvn:deploy, maven will only upload the original-jar to the Raspberry Pi to the file path of groupId, artifactId and version.

What can I do to only upload a single jar without a directory.

1

1 Answers

0
votes

When you use the Deploy plugin Maven will automatically deploy it in a folder named after your artifact groupdId, artifactId, etc. This behavior is built-in and you cannot override it, there's not much you can do about it.

However you can use the Wagon plugin to directly upload via SSH on your RPI with a configuration like:

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

The upload will bind to the deploy phase, you can then run mvn deploy as with the Deploy plugin to have your JAR uploaded on your machine.

Note that if you are using Maven 3 you'll have to update your project dependencies. As per the Usage page:

This plugin does not work with Maven 3.0.x and 3.1.x out of the box due to missing the following libraries in it distribution: commons-io-2.x, common-lang-2.x, and jsoup-1.x. You can invoke wagon:update-maven-3 to add the missing files to $MAVEN_HOME/lib. See WAGON-407 for details