1

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?

Dmytro Chasovskyi
  • 3,209
  • 4
  • 40
  • 82
  • 1
    If you use `mvn install` the jar goes into your M2 folder, and every dev must follow the same step. Instead, you can use `mvn deploy` to put that jar to your company repo (eg Nexus?), and edit your `pom.xml` to use the "released" jar. See eg. https://stackoverflow.com/questions/1912867/upload-jar-to-respository – Daniele Feb 20 '19 at 20:08
  • @Daniele Is it any way to force it to go into project directory (instead of `.m2`) and write script, so each developer will be able to run and use `jar`s locally? – Dmytro Chasovskyi Feb 20 '19 at 20:52
  • 1
    Uhm, if you really need to place the jar in a project folder, you can specify that the dependency is local using the (very discouraged) scope `system` and specifying a `systemPath` , like in the question of https://stackoverflow.com/questions/10935135/maven-and-adding-jars-to-system-scope – Daniele Feb 20 '19 at 21:30

1 Answers1

1

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.

Amit
  • 33,847
  • 91
  • 226
  • 299