简体   繁体   English

如何在基于 Maven 的 Java 项目中安装 MWS 库?

[英]How to work install MWS library in Java, Maven based project?

It's the first time I am trying to use MWS library with Java .这是我第一次尝试将 MWS 库与Java一起使用。 I have small Spring Boot application Maven -based.我有基于Maven的小型Spring Boot应用程序。 I wanted to install mws from https://mvnrepository.com/ by mws I found several libraries located on Fishbowldev .我想安装mwshttps://mvnrepository.com/通过mws我发现位于几个库Fishbowldev At the time of writing this post, repo seems to be unavailable.在撰写本文时,repo 似乎不可用。 Example of library I wanted to use.我想使用的示例。

At the moment, my pom.xml looks the following way:目前,我的pom.xml看起来如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>io.test.api</groupId>
    <artifactId>test-api</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>test-api</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <repositories>
        <repository>
            <id>fishbowldev</id>
            <name>Fishbowldev Repository</name>
            <url>http://murky.fishbowldev.com:8081/nexus/content/repositories/releases/</url>
            <releases>
               <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- MWS libraries -->
        <!-- https://mvnrepository.com/artifact/amazon/mws-client -->
        <dependency>
            <groupId>amazon</groupId>
            <artifactId>mws-client</artifactId>
            <version>1.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/amazon/mws-sellers -->
        <dependency>
            <groupId>amazon</groupId>
            <artifactId>mws-sellers</artifactId>
            <version>2011-07-01</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/amazon/mws-orders -->
        <dependency>
            <groupId>amazon</groupId>
            <artifactId>mws-orders</artifactId>
            <version>2013-09-01-2015-09-25</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Is there any other way except of manual installation to add this library to my pom.xml file?除了手动安装之外,还有其他方法可以将此库添加到我的pom.xml文件中吗?

Step 1: Configure the maven-install-plugin with the goal install-file in your pom.xml步骤 1:使用pom.xml的目标install-file配置maven-install-plugin

<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.务必请编辑该file根据您的实际文件路径(建议在路径是将一些文件夹内的这些外部非Maven的罐子,让我们说lib ,并把这个lib文件夹的项目中,以使用特定项目的相对路径和避免添加系统特定的绝对路径。

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:第 2 步:一旦您在pom.xml文件中配置了如上所示的maven-install-plugin ,您必须像往常一样在pom.xml使用这些 jar:

    <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.请注意, maven-install-plugin只会将您的外部 jar 复制到您本地的.m2 maven 存储库。 That's it.就是这样。 It doesn't automatically include these jars as maven dependencies to your project.它不会自动将这些 jar 作为 Maven 依赖项包含到您的项目中。

It's a minor point, but sometimes easy to miss.这是一个小点,但有时很容易错过。

I didn't find any exact solution for my question.我没有为我的问题找到任何确切的解决方案。 Instead I found a workaround.相反,我找到了一个解决方法。 The project that Mavenised the old MWS Java SDK on GitHub .GitHub 上对旧MWS Java SDK进行Mavenised的项目。

The solution doesn't create any fancy way of working with MWS it is just a convenient wrapper for Maven -based projects.该解决方案不会创建任何使用MWS奇特方式,它只是基于Maven的项目的方便包装器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM