web application deployment (Tomcat, springboot deployment) Tomcat web application deployment of four methods

Reprinted from: https://www.cnblogs.com/haimishasha/p/10791454.html

core content

1. There are four ways to deploy Web applications in Tomcat, are:

(1) using a Tomcat automatically deployed (OR WAR packet copy item directly copied to the webapps)

(2) using the console (deployment deploy tomcat area manager of the console )

(3) add custom Web deployment files (% Tomcat_Home% \ conf \ Catalina \ localhost \ AppName.xml )

(4) to manually modify% Tomcat_Home% \ conf \ server.xml file to deploy a web application

2.SpringBoot WEB project two release and deployment

(1) by the WAR

(2) (recommended official website) by JAR package

3.springboot There are 3 hot deployment:
(1) using the springloaded pom.xml configuration file, using mvn spring-boot: run Start
(2) using the local load springloaded start configuration parameters jvm -javaagent: <jar packet address> -noverify
(3) use devtools kit, simple operation, but every time you need to re-deploy

1. Tomcat There are four ways to deploy Web applications

The first way: using the automatic deployment of Tomcat

        Tomcat using the automatic deployment is the simplest, most common way. If a web application structure is D: \ workspace \ WebApp \ AppName \ WEB-INF \ *, WebContent class AppName as long as a Web application directly thrown% Tomcat_Home% \ webapps folder under the system will direct the web application deployed to Tomcat. So I will not repeat them here.

 

The second way: use the console to deploy

        If a web application structure is D: \ workspace \ WebApp \ AppName \ WEB-INF \ *, use the console to deploy as follows: enter the tomcat manager console deploy region - Type "XXX" in the Context path in ( can be named) - in WAR or Directory URL: type D: \ workspace \ WebApp \ AppName ( represented to find the web application under this path) - click on the deploy button.

  

          Then % Tomcat_Home% \ webapps will automatically appear in a file named XXX folder path, the content that is D: \ workspace \ WebApp \ AppName content, but only the name is XXX (which is in front of Type XXX in Context path the result of).

Described above using the console to deploy the essence is still using the automatic deployment of Tomcat.

The third way: to increase custom Web deployment file

        If a web application structure is D: \ workspace \ WebApp \ AppName \ WEB-INF \ *, this deployment a little more complex, we need to % Tomcat_Home% \ conf create a new folder under the path again catalina-- in which the new a localhost folder - Finally, create a new XML file, an increase of two new XML file and directory: % Tomcat_Home% \ conf \ Catalina \ localhost \ Web application configuration file .xml, the file is to deploy Web application configuration file .

  For example, we create a new % Tomcat_Home% \ conf \ Catalina \ localhost \ XXX.xml,   the contents of the file are as follows:

 <Context path = "/ XXX" reloadable = "true" docBase = "D: \ workspace \ WebApp \ AppName" workDir = "D: \ workspace \ WebApp \ work" /> Note: (1) in the above code workDir represents the Web application deployment disposed after working directory (JSP Web applications can be compiled into Servlet found therein), if used as the IDE Eclipse, generally can be artificially provided in the work directory WebApp. If the custom web deployment files XXX.xml not specified in the workdir, the web application will be deployed in the default% Tomcat_Home% \ work \ Catalina \ localhost \ path XXX under the new name of the file in the folder. (JSP Servlet can be compiled into a Web application in which to find) (2) Context path that is specified virtual path name of the web application. DocBase specify the source path to deploy Web applications.

        In fact, developers can use eclipse plugin installed Tomcat deployment file automatically created to deploy Web applications without having to manually create the file, as follows: 

1. Open Eclipse-- open the window menu bar select preference (Preferences) - Left selection Tomcat, illustrated as follows:

        2. Select see declaration mode (Context declaration mode) highlighted above figure drawn Context Context Files to add custom file deployed in the form of a web application deployment - Contexts directory and the parent directory file specified above (i.e., % % Tomcat_Home \ conf \ Catalina \ localhost  ) - click Apply or OK.

        3. 完上述步骤,再选中Web项目右键点击properties(属性)——选择右侧的Tomcat ,如下图所示:

      4. 勾上"Is a Tomcat project"前的checkbox,将项目关联至Tomcat。

在Context name中填入XXX,即Web应用自定义部署文件名和Context path名。

在Subdirectory to set as web application root (optional)中填入要部署的Web应用的实际路径(即WEB-INF上级目录)。

注意:Eclipse会自动地将workdir设置在Workspace\WebApp\work下。

如此便自动创建了%Tomcat_Home%\conf\Catalina\localhost\XXX.xml 文件。启动Tomcat 即可自动部署Web应用。

第四种方式:手动修改%Tomcat_Home%\conf\server.xml文件来部署web应用

         此方法即打开%Tomcat_Home%\conf\server.xml文件并在其中增加以下元素:

   <Context docBase="D:\workspace\WebApp\AppName" path="/XXX" debug="0" reloadable="false" />

         然后启动Tomcat即可。

         当然如果使用Eclipse,在Eclipse中的设置也有改变:打开菜单栏window选择preference(首选项)——左侧选择Tomcat——可以看到上图中高亮画出的Context declaration mode(Context 声明模式)中选择以Server.xml文件来部署web应用。

  

2. SpringBoot WEB项目两种发布和部署方式

(1)通过WAR包

(2)通过JAR包(官网推荐)

1. WAR

  传统的部署方式:将项目打成war包,放入tomcat 的webapps目录下面,启动tomcat,即可访问。

  步骤1:在pom.xml文件中将jar修改为war【<packaging>war</packaging>】

  步骤2:在pom.xml文件中将配置文件添加tomcat模块【】  

<!-- 不使用内置的tomcat  -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 移除tomcat插件 -->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<!-- 移除之后会报错,加入下面的依赖 -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <scope>provided</scope>
</dependency>


<!-- 使用内置的tomcat  -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
      <artifactId>provided</artifactId><!--仅用于编译和测试-->
</dependency>

  步骤3:在main方法处的启动类基继承

   

  步骤4:在pom.xml点击右键选择Maven install,会在target文件夹中生成xxx.war包

 

2. JAR

  步骤1:在pom.xml文件点击右键,选择“Maven install”,然后刷新target文件夹,在target中会产生xxx.jar包。

  步骤2:然后在cmd终端输入代码:java -jar xxx.jar ,发布成功

  步骤3:在浏览器输入localhost等url进行访问

3. JAR VS WAR

  

4. 线上部署

方式一:java -jar vodmanager.jar &           后台关闭后,服务不会中断

方式二:nohup java -jar vodmanager.jar &  后台关闭后,服务不会中断,并且会把输出的文件信息写在当前目录下的nohup文件中。

3. SpringBoot热部署三种方式

springboot有3中热部署方式:
1.使用springloaded配置pom.xml文件,使用mvn spring-boot:run启动
2.使用springloaded本地加载启动,配置jvm参数   -javaagent:<jar包地址> -noverify
3.使用devtools工具包,操作简单,但是每次需要重新部署

第一种:使用springloaded配置pom.xml文件

1. 原来的pom.xml文件中添加如下配置
<build>
     <plugins>
          <plugin>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-maven-plugin</artifactId>
               <dependencies>
                    <dependency>
                         <groupId>org.springframework</groupId>
                         <artifactId>springloaded</artifactId>
                         <version>1.2.6.RELEASE</version>
                    </dependency>
               </dependencies>
          </plugin>
     </plugins>
</build>
复制代码

        注意:需要在spring-boot-maven-plugin中添加dependency

 
2.启动方式变为maven启动:在项目的文件夹dos窗口输入命令mvn spring-boot:run
 
    注意:停止服务是只能使用ctrl+c, 如果设置后台启动,需要kill进程

第二种:springloaded本地加载启动,配置jvm参数

1.下载 springloaded工具包到一个指定目录(或直接就用maven仓库地址了)
2.在启动项目时,在jvm参数中输入命令
  -javaagent:D:\Maven\repository\org\springframework\springloaded\1.2.6.RELEASE\springloaded-1.2.6.RELEASE.jar  -noverify
 
扩展: -javaagent:命令后面跟冒号,意思是在执行main方法之前执行特定代码
       -noverify 关闭java字节码校验功能

第三种:使用devtools工具包

1.在pom.xml中添加依赖
<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-devtools</artifactId>
     <optional>true</optional>
</dependency>
2.启动项目
 

总结

在开发测试环境下第三种可取,方便快捷
在生产环境下,建议使用第二种,使用脚本启动

抄录网址

  1. tomcat部署web应用的4种方法
  2. Spring Boot项目的两种发布方式
  3. 开发笔记9:SpringBoot打包部署的三种方式
  4. Spring-Boot启动方式,以及线上部署

Guess you like

Origin www.cnblogs.com/tuanz/p/11204971.html