java - 如何在 Linux 中部署 Springboot 应用程序以及 Maven 依赖项
问题描述
我创建了一个 Spring Boot java 应用程序(REST 服务),它在内部使用 Tomcat 作为 Windows 机器上的 Web 服务器,使用 Eclipse 作为 IDE。它使用 JDK 1.8 和 Maven 作为构建系统。在这里,我创建 jar 文件(以 Maven 安装方式运行),然后在我的 Windows 机器中从命令提示符调用该 jar 文件。我在我的 Windows 机器上使用 POSTMAN 测试这些 REST 服务。
现在我必须让它在没有 UI 的 Linux 机器上运行。你能帮我如何在 Linux 机器上实现相同的目标,以及如何在 Linux 机器上获得这些依赖项。
解决方案
首先,确保您的 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>
推荐阅读
- flutter - 如何将参数传递给flutter integration_test?
- r - tibble 数据帧中原子向量的访问频率
- python - 将py文件编译为pyc导致程序失败
- hive - 在 Streamsets DC 中读取 hive 表(或 parquet 格式的 HDFS 数据)
- python - cv2_imshow collab 没有显示使用 cnn+l 预测视频的任何内容;stm 模型
- list - 列出 0 的负索引;x[-0]
- geoserver - 更新磁盘上的 global.xml 不会更新 geoserver 配置
- c# - 如何从 linq 查询中提取特定值?
- monaco-editor - DiagnosticsOptions typescript 怎么用?
- javascript - Discord 事件处理程序错误,我不知道为什么