【问题标题】:How to work install MWS library in Java, Maven based project?如何在基于 Maven 的 Java 项目中安装 MWS 库?
【发布时间】:2020-05-03 22:49:19
【问题描述】:

这是我第一次尝试将 MWS 库与Java 一起使用。我有基于 Maven 的小型 Spring Boot 应用程序。我想通过mwshttps://mvnrepository.com/ 安装mws 我在Fishbowldev 上找到了几个库。在撰写本文时,repo 似乎不可用。我想使用的library 示例。

目前,我的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>

除了手动安装还有其他方法可以将此库添加到我的pom.xml 文件吗?

【问题讨论】:

    标签: java maven amazon-mws fishbowl


    【解决方案1】:

    第 1 步:在您的 pom.xml 中配置 maven-install-plugin 和目标 install-file

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

    确保根据您的实际文件路径编辑file 路径(建议将这些外部非maven jar 放在某个文件夹中,比如lib,并将此lib 文件夹放在您的项目中,这样至于使用项目特定的相对路径,避免添加系统特定的绝对路径。

    第 2 步:pom.xml 文件中如上所示配置maven-install-plugin 后,您必须像往常一样在pom.xml 中使用这些罐子:

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

    请注意,maven-install-plugin 仅将您的外部 jar 复制到您的本地 .m2 maven 存储库。而已。它不会自动将这些 jars 作为 maven 依赖项包含到您的项目中。

    这是一个小问题,但有时很容易错过。

    【讨论】:

      【解决方案2】:

      我没有为我的问题找到任何确切的解决方案。相反,我找到了一种解决方法。 MavenisedMWS Java SDKGitHub的项目。

      该解决方案不会创建任何使用 MWS 的奇特方式,它只是对基于 Maven 的项目的方便包装。

      【讨论】:

        猜你喜欢
        • 2021-11-04
        • 1970-01-01
        • 2019-07-14
        • 1970-01-01
        • 2017-08-05
        • 2018-02-05
        • 2010-10-25
        • 2016-08-04
        • 1970-01-01
        相关资源
        最近更新 更多