【问题标题】:How to deploy Springboot app in Linux along with Maven dependencies如何在 Linux 中部署 Springboot 应用程序以及 Maven 依赖项
【发布时间】:2019-07-05 17:59:48
【问题描述】:

我创建了一个 Spring Boot java 应用程序(REST 服务),它在内部使用 Tomcat 作为 Windows 机器上的 Web 服务器,使用 Eclipse 作为 IDE。它使用 JDK 1.8 和 Maven 作为构建系统。在这里,我创建 jar 文件(Run as Maven Install),然后在我的 Windows 机器中从命令提示符调用该 jar 文件。我在我的 Windows 机器上使用 POSTMAN 测试这些 REST 服务。

现在我必须让它在没有 UI 的 Linux 机器上运行。你能帮我如何在 Linux 机器上实现同样的功能,以及如何在 Linux 机器上获得这些依赖项。

【问题讨论】:

  • 将你的 jar 文件复制到 linux 机器上,你就可以开始了。但是,你必须在 Linux 机器上安装 java 和 maven。
  • 你使用spring-boot-maven-plugin并打包成jar文件吗?如果是这样,您只需要运行您的应用程序的 jar 文件和 JRE ...
  • 只需启动一个spring boot app:java -jar spring-boot-app.jar..

标签: java linux maven spring-boot


【解决方案1】:

首先,确保您的 Linux 服务器已安装 Java。最匹配您本地的 java 版本。

其次,利用maven插件生成一个shell脚本,可以启动这个项目。

下面是一个例子

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>appassembler-maven-plugin</artifactId>
    <version>1.10</version>
    <!-- bind to package phase -->
    <executions>
        <execution>
            <id>make-appassembly</id>
            <phase>package</phase>
            <goals>
                <goal>assemble</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <!-- set alternative assemble directory -->
        <assembleDirectory>${project.build.directory}/${project.artifactId}-${project.version}
        </assembleDirectory>
        <environmentSetupFileName>envSetup.sh</environmentSetupFileName>
        <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
        <repositoryLayout>flat</repositoryLayout>
        <repositoryName>lib</repositoryName>
        <platforms>
            <!-- <platform>windows</platform> -->
            <platform>unix</platform>
        </platforms>
        <!-- Extra JVM arguments that will be included in the bin scripts -->
        <extraJvmArguments>-Dlog4j.configuration=file:$BASEDIR/etc/log4j.properties
            -Dapplication.properties=file:$BASEDIR/etc/XXX.properties
            -Xms2048m
            -Xmx12288m -server -showversion -XX:+UseConcMarkSweepGC
            -DXXX.log.dir=XXX
            -DXXX.app.id=XXX
        </extraJvmArguments>
        <programs>
            <program>
                <mainClass>com.xxx.App</mainClass>
                <name>xxx.sh</name>
            </program></programs>
    </configuration>
</plugin>

【讨论】:

    猜你喜欢
    • 2016-02-27
    • 2015-09-17
    • 2011-04-25
    • 2018-04-10
    • 1970-01-01
    • 2016-08-24
    • 2013-10-31
    • 2015-10-22
    • 2010-10-08
    相关资源
    最近更新 更多