0

I am using this code to upload a JAR file to a Server right after the Install phase:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
      <execution>
        <id>server-deployment</id>
        <phase>install</phase>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>D:\my-folder\pscp.exe -r -i D:\my-folder-conf\user.ppk D:\my-folder-jar\file-1.1.0.jar ubuntu@X.XX.XX.XXX:/usr/local/folder1/jar/file-1.1.0.jar</executable>
    </configuration>
  </plugin>

The command:

D:\my-folder\pscp.exe -r -i D:\my-folder-conf\user.ppk D:\my-folder-jar\file-1.1.0.jar ubuntu@X.XX.XX.XXX:/usr/local/folder1/jar/file-1.1.0.jar

Works from Windows Console normally and the file is uploaded, but when I execute the very same command with the exec-maven-plugin, it fails with the message: CreateProcess error=2, The system cannot find the file specified. If I am providing full paths and extensions to all files, how does this happen? Is there any solution for this=

Solution:

I ended up using the approach of @xerx593, thanks for your help, here bellow is the final solution:

<configuration>
  <executable>D:\my-folder\pscp.exe</executable>
  <arguments>
    <argument>-r</argument>        
    <argument>-i</argument>      
    <argument>D:\my-folder-conf\user.ppk</argument>       
    <argument>${project.build.directory}/${project.build.finalName}.jar</argument> 
    <argument>ubuntu@X.XX.XX.XXX:/usr/local/folder1/jar/${project.build.finalName}.jar</argument>  
  </arguments>
</configuration>
Joe Almore
  • 4,036
  • 9
  • 52
  • 77
  • 1
    Simply the wrong tool for it.. Use something else like Ansible / CI/CD solution but don't try to abuse Maven for that...Already having absolute paths in it makes it impossible to use for others or on a CI solution... – khmarbaise Jan 05 '22 at 14:19

1 Answers1

1

Please try:

    <configuration>
      <executable>D:\my-folder\pscp.exe</executable>
      <arguments>
        <argument>-r</argument>        
        <argument>-i</argument>      
        <argument>D:\my-folder-conf\user.ppk</argument>       
        <argument>D:\my-folder-jar\file-1.1.0.jar</argument> 
        <argument>ubuntu@X.XX.XX.XXX:/usr/local/folder1/jar/file-1.1.0.jar</argument>  
      </arguments>
    </configuration>

...as documented (& shown) instead.

xerx593
  • 12,237
  • 5
  • 33
  • 64