Spring boot project war package deployment

It's Feng Jirong 2021-04-16 19:54:31
spring boot project war package


Service deployment

Record the reason

Will local SpringBoot The project by war The package is deployed to the virtual machine , Verify the server deployment .

Use war The package is to facilitate the replacement of configuration files and so on .

Tools

object edition
Spring Boot 2.4.0
VMware Workstation Pro 16
Git 2.9.4
maven 3.3.9
JDK jdk1.8.0_281
Tomcat 9.0.45
Redis 6.2.1

Tomcat Version needs to be associated with SpringBoot The built-in version is consistent with the large version , Otherwise there will be problems

The virtual machine installation is not detailed here .

Git

  • Enter the cd /usr/local/src Catalog , Enter the download link :

    wget https://www.kernel.org/pub/software/scm/git/git-2.9.4.tar.gz
    
  • decompression

    tar -zxvf git-2.9.4.tar.gz
    
  • Installation and compilation Git Package needed for ( One sentence at a time )

    yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
    yum install gcc perl-ExtUtils-MakeMaker
    
  • Delete existing Git

    yum remove git
    
  • Compilation and installation

     Go to the root directory :cd /usr/local/src/git-2.9.4
    The installation to /usr/local/git Catalog :./configure --prefix=/usr/local/git
    Compilation and installation :make && make install
    
  • Create soft chain :

    ln -s /usr/local/git/bin/* /usr/local/bin/
    
  • Verify that the installation is complete

    git --version
    

maven

  • Check maven Whether to install

    mvn -v
    
  • stay /usr/local/src Download under directory maven Compressed package

    wget https://archive.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
    
  • Decompress the package

    tar -zxvf apache-maven-3.3.9-bin.tar.gz
    
  • Move to /usr/local

    mv apache-maven-3.3.9 /usr/local/maven3
    
  • Configure environment variables

    • Open environment variable file profile

      vim /etc/profile
      
    • Add environment variables at the end

      export MAVEN_HOME=/usr/local/maven3
      export PATH=$MAVEN_HOME/bin:$PATH
      
    • tips: Here's the preparation part Linix Text editing commands

      i Enter edit mode - Start typing... At the cursor position
      esc Exit edit mode
      :wq After exiting edit mode, save the file and push it out
      more https://www.linuxprobe.com/linux-vim-commend.html
      
    • Make configuration effective

      source /etc/profile
      
  • Check if the installation is successful

    mvn -v
    

JDK

  • Check for installation

    java -version
    
  • install JDK It is recommended to use after downloading the installation package locally winSCP And so on software uploads from the local to the server , Be sure to download the correct version (jdk-8uxxx-linux-x64.tar.gz).JDK The download address is as follows :

    https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
    
  • Will download okay JDK The installation package is uploaded to the server /usr/local/src Under the table of contents , Unzip after upload .

    tar -zxvf jdk-8u201-linux-x64.tar.gz
    
  • Will unzip OK JDK Move to /usr/local Next

    mv jdk1.8.0_201 /usr/local
    
  • Configure environment variables

    • Go to configuration file

      vim /etc/profile
      
    • After adding the following environment variable configuration, save and exit :

      export JAVA_HOME=/usr/local/jdk1.8.0_201
      export JRE_HOME=/usr/local/jdk1.8.0_201/jre
      export PATH=$JAVA_HOME/bin:$PATH
      export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
      
    • Make configuration effective

      source /etc/profile
      
  • Verify the installation

    java -version
    

Tomcat

  • download Tomcat To the same level , adopt filezilla Wait for tools to upload to /usr/local in

    https://tomcat.apache.org/download-90.cgi#9.0.45
    
  • decompression

    tar -zxvf apache-tomcat-9.0.45.tar.gz
    
  • If you have obsessive-compulsive disorder , The compressed package can be deleted

    rm /usr/local/apache-tomcat-9.0.45.tar.gz
    
  • start-up

    sh /usr/local/apache-tomcat-9.0.45/bin/startup.sh
    
  • close

    sh /usr/local/apache-tomcat-9.0.45/bin/shutdown.sh
    
  • Real time log view

    tail -500f /usr/local/apache-tomcat-9.0.45/logs/catalina.out
    

Redis

  • Download it locally redis Upload to the server or download directly from the server . I choose the stable version to download , To the virtual machine .

    https://redis.io/download
    
  • decompression

    tar -zxvf redis-6.2.1.tar.gz
    
  • Yum install gcc rely on , And compile and install redis

    cd /usr/local/redis-6.2.1
    yum install gcc
    make MALLOC=libc
    cd src && make install
    
  • start-up redis( In addition, it can be configured as a service )

    ./redis-server
    

Connect different problems to solve

  1. ping ip

    ip Different check firewalls

  2. The virtual machine checks whether the port number is on

    After modifying the port, you need to restart the firewall service to take effect

    centos8 Check that the port is on
    firewall-cmd --query-port=8080/tcp
    Open port
    firewall-cmd --zone=public --add-port=8080/tcp --permanent
    service iptables restart :
    systemctl restart firewalld.service
    

    here centos8 The port number is different from the previous version .

    In the beginning, virtual machines Tomcat When I got up, I windows visit 8080 Port failure , According to these two steps, the visit is successful .

Project preparation

If using Idea Build a new project , You can choose how to package when you create it , If you build with jar package , We need some changes .

The new project

When building, choose the packaging method as war package

Jar Package items

It means that the packing method is jar Project .

  • You need to ignore the built-in Tomcat, The local runtime needs to use . So the local runtime turns off annotations .

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- Ignore the built-in tomcat Containers -->
    <exclusions>
    <exclusion>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    
  • Ignore the built-in Tomcat At the same time , Need to add extra servlet rely on

    <!-- Because of ignoring the built-in tomcat Containers , Therefore use javax.servlet Method requires additional dependencies -->
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    </dependency>
    
  • add to war Package name , Ignore packaging files ( Optional )

    <build>
    <finalName>demo</finalName>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
    <excludes>
    <!-- Ignore the custom class configuration prompt tool when packaging -->
    <exclude>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    </exclude>
    </excludes>
    </configuration>
    </plugin>
    </plugins>
    </build>
    

pack

There are two ways .

  • Idea Click on Bulid>Build Artifacts> choice demo.war

  • Use maven The packing order of

    mvn clean package
    

start-up

  • Will be packed war Package pass filezilla Etc. to the virtual machine tomcat Under the webapp Directory

  • Start... On the virtual machine Tomcat, And access , The response to the request is successful

    http://192.168.xxx.xxx:8080/demo/
    

Step on the pit

Tomcat After starting , Use the following log command to monitor project startup , When problems arise, it's intuitive .

tail -500f /usr/local/apache-tomcat-9.0.45/logs/catalina.out
  • Regardless of the port number of the local configuration of the project 、 visit url What is it? , Deploying to a virtual machine uses Tomcat The port number of plus war Package name , Such as 8080/demo/

  • Because I'm accessing a local database , So you need to modify the database address in the project configuration file , Deployment project error

    java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect...
    

    This is because the database server does not give access to the service deployment server , Please refer to https://blog.csdn.net/xionglangs/article/details/50385057

版权声明
本文为[It's Feng Jirong]所创,转载请带上原文链接,感谢
https://javamana.com/2021/04/20210416181545303u.html

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云