springBoot项目打包、部署

1、项目打包的maven插件

 <plugin>
               <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.5.4</version>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>

2、打包方式

  <!--添加打包方式-->
    <packaging>jar</packaging>

3、maven命令打包

在这里插入图片描述
在这里插入图片描述

4、部署上服务器

1、首先需要注意springboot项目的jdk版本与服务器上安装的jdk版本相差不大
2、把打包完成的springboo项目jar包上传至服务器,然后再jar包所在根目录运行如下命令即可

 java -jar shrimp-0.0.1-SNAPSHOT.jar

3、运行命令后可能会出现以下错误:

第一、
出现这样子的错误可能是因为项目端口冲突,在application.yaml中修改端口即可

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
        If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
        If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

第二、
springboot项目的jdk版本与服务器上安装的jdk版本相差太大

[root@hecs-x-large-2-linux-20210416124557 server]# vim start.sh
[root@hecs-x-large-2-linux-20210416124557 server]# chmod 777 start.sh
[root@hecs-x-large-2-linux-20210416124557 server]# nohup ./start.sh &
[1] 3512596
[root@hecs-x-large-2-linux-20210416124557 server]# nohup: ignoring input and appending output to 'nohup.out'
cat nohub.out
cat: nohub.out: No such file or directory
[1]+  Done                    nohup ./start.sh
[root@hecs-x-large-2-linux-20210416124557 server]# ls
apache-tomcat-9.0.46  data  file.log  mysql  nginx  nohup.out  panel  php  phpmyadmin  pure-ftpd  shrimp-0.0.1-SNAPSHOT.jar  start.sh  stop  tomcat  tomcat8
[root@hecs-x-large-2-linux-20210416124557 server]# cat nohub.out
cat: nohub.out: No such file or directory
[root@hecs-x-large-2-linux-20210416124557 server]# vim nohub.out
[root@hecs-x-large-2-linux-20210416124557 server]# cat file.log
[root@hecs-x-large-2-linux-20210416124557 server]# cat /www/server/nohup.out
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/ice/ShrimpApplication has been compiled by a more recent version of the Java Runtime (class file version 60.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)

在这里插入图片描述
解决方法:
1、修改springboot项目的jdk版本
2、修改服务器的jdk版本
一些linux命令
检查是否安装jdk

rpm -qa |grep jdk
rpm -e --nodeps   文件名

安装与项目版本一样的jdk的rpm文件

rpm -ivh 文件名
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫风魅影

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值