如何使用外部jar和jar包装来部署spring boot应用程序

时间:2020-06-13 09:58:43

标签: spring spring-boot maven jar fatjar

我的应用程序已成功在localhost上运行,但是当我在AWS服务器上部署应用程序时,它无法在线运行。我有一个paytm-checksum-2.0的外部JAR。使用外部JAR部署Spring Boot应用程序应该怎么做? 我已经将我的应用程序转换为一个jar文件,但是无法部署...

文件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 https://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.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>Spring-payment-integration</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Spring-payment-integration</name>
    <description>Payment integration with paytm</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

1 个答案:

答案 0 :(得分:0)

我在pom.xml中看不到此自定义jar,您可能已将其添加到IDE配置中(或仅在本地工作的任何其他方法),因此尽管它可能在远程本地工作,但不会目前,您将无法引用它。 从我看来,这是官方的jar:https://github.com/Paytm-Payments/Paytm_Web_Sample_Kit_Java/tree/master/Java%20Kit%201.8

但是,在maven https://mvnrepository.com/artifact/com.paytm上托管的paytm工件上似乎并不存在。因此,您现在有2个选择:

  1. 将罐子添加到联系仓库或公共仓库(例如maven)并从那里引用它,这非常复杂(https://www.baeldung.com/install-local-jar-with-maven/

  2. 您可以将此自定义jar与springboot jar打包在一起。

a。将其添加到您的项目位置。<file>${basedir}/dependencies/PaytmChecksum.jar</file>

b。现在将其添加到您的pom

<build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install-Transformation lib</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${basedir}/dependencies/PaytmChecksum.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>org.paytm</groupId>
                            <artifactId>paytmchecksum</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

c。清理项目mvn clean

d。现在使用

引用文件
<dependency>
    <groupId>org.paytm</groupId>
    <artifactId>paytmchecksum</artifactId>
    <version>1.0</version>
</dependency>

e。使用mvn clean install进行构建 现在,打包的jar将包含您的Paytm jar。