How to install MWS locally into Spring Boot project managed by Maven?

307 Views Asked by At

I am trying to plug MWS libraries into my small Spring Boot application. I tried to find solution into this post. So far, no ideas out of there.

Is there are any way I can plugin 3rd party into my pom.xml file and make it easily installable into other developers machines? I tried this solution and also this guide.

I put MWS Java client files under src/dist and tried to install as mvn install:install-file -Dfile="/<my-path>/dist/MWSClientJavaRuntime-1.0.jar" -DgroupId=amazon -DartifactId=mws-client -Dversion=1.0 -Dpackaging=jar and got the response:

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building test-api 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install-file (default-cli) @ hiccasoft-api ---
[INFO] pom.xml not found in MWSClientJavaRuntime-1.0.jar
[INFO] Installing /home/test/<part-of-my-path>/dist/MWSClientJavaRuntime-1.0.jar to /home/test/.m2/repository/amazon/mws-client/1.0/mws-client-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.661 s
[INFO] Finished at: 2019-02-20T19:33:26+01:00
[INFO] Final Memory: 13M/300M
[INFO] ------------------------------------------------------------------------

What should I do with this? How to work with "installed" locally 3rd library and how to distribute it between other developers?

1

There are 1 best solutions below

0
Amit On

Step 1: Configure the maven-install-plugin with the goal install-file in your pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <executions>
        <execution>
            <id>install-external-non-maven-jar-MWS-Client-into-local-maven-repo</id>
            <phase>clean</phase>
            <configuration>
                <repositoryLayout>default</repositoryLayout>
                <groupId>com.amazonservices.mws</groupId>
                <artifactId>mws-client</artifactId>
                <version>1.0</version>
                <file>${project.basedir}/lib/MWSClientJavaRuntime-1.0.jar</file>
                <packaging>jar</packaging>
                <generatePom>true</generatePom>
            </configuration>
            <goals>
                <goal>install-file</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Make sure to edit the file path based on your actual file path (recommended is to place these external non-maven jars inside some folder, let's say lib, and place this lib folder inside your project so as to use project-specific relative path and avoid adding system specific absolute path.

Step 2: Once you have configured the maven-install-plugin as shown above in your pom.xml file, you have to use these jars in your pom.xml as usual:

    <dependency>
        <groupId>com.amazonservices.mws</groupId>
        <artifactId>mws-client</artifactId>
        <version>1.0</version>
    </dependency>

Note that the maven-install-plugin only copies your external jars to your local .m2 maven repository. That's it. It doesn't automatically include these jars as maven dependencies to your project.

It's a minor point, but sometimes easy to miss.

This way, all the developers will get these dependencies on their machines as well without doing anything.