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 文件名