IDEA开发Sping MVC的热部署配置

IDEA开发Sping MVC的热部署配置

1. pom.xml修改的配置

<!--首先配置packaging标签为war格式-->
<packaging>war</packaging>

<!--配置统一编码格式UTF-8-->
<properties>
     <project.build.soureEncoding>UTF-8</project.build.soureEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<!--增长servlet和jsp的provided范围依赖-->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>  
    <scope>provided</scope>
</dependency>

<dependency>
     <groupId>javax.servlet.jsp</groupId>
     <artifactId>jsp-api</artifactId>
     <version>2.2.1-b03</version>
     <scope>provided</scope>
</dependency>

<!--因为使用无web.xml的纯注解开发,须要maven-war-plugin插件须要配置以下-->
<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-war-plugin</artifactId>
     <version>3.0.0</version>
     <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

<!--使用内嵌的tomcat的maven插件来实现热加载和热部署-->
<plugin>
	<groupId>org.apache.tomcat.maven</groupId>
    	<artifactId>tomcat7-maven-plugin</artifactId>
    	<version>2.2</version>
    	<configuration>
             <!--内嵌tomcat配置信息-->
             <port>8080</port>
             <path>/${project.artifactId}</path> <!--设置项目访问路径-->
             <uriEncoding>UTF-8</uriEncoding> <!--设置uri编码格式UTF-8-->
             <server>tomcat7</server> <!--配置内嵌tomcat7-->
             <!--JSP页面会自动热加载,classes须要以下配置后才能自动热加载-->
             <contextReloadable>true</contextReloadable>
			 
             <!--远程部署-->
             <url>http://www.guxiaotu.club:8888/manager/text</url>
             <username>admin</username>
             <password>admin</password>
        </configuration>
</plugin>

使用内嵌tomcat7服务器,运行命令mvn tomcat7:run,远程热部署项目,运行命令mvn tomcat7:redeployhtml

2. 配置远程tomcat

tomcat8.5以后版本,客户端进入tomcat首页点击manager想进行项目管理发现没有登陆提示,直接跳转403或401权限错误java

提示:web

By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager's context.xml fileapache

==修改webapps/magager/META-INF/context.xml,注释如下内容,禁止只容许本机访问==api

<!--
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
     allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->

==同时修改conf/tomcat-users.xml,添加用户和规则==tomcat

<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<user username="admin" password="admin"roles="admin,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status"/>

manager-gui:容许访问html接口(即URL路径为/manager/html/)服务器

manager-script:容许访问纯文本接口(即URL路径为/manager/text/)app

manager-jmx:容许访问JMX代理接口(即URL路径为/manager/jmxproxy/)webapp

manager-status:容许访问Tomcat只读状态页面(即URL路径为/manager/status/)jsp

admin-gui:访问Host Manager(HTML UI接口)

admin-script:访问Host Manager(纯文本接口)

特别须要说明的是:manager-gui、manager-script、manager-jmx均具有manager-status的权限,也就是说,manager-gui、manager-script、manager-jmx三种角色权限无需再额外添加manager-status权限,便可直接访问路径/manager/status/。

3. 使用外部Tomcat或者jetty runer插件配置热启动

3.1 tomcat

​ IDEA配置tomcat比较简单,若是须要热部署jsp页面须要 on 'Update' action设置为Update classes and resources。classes类热部署需用到JRebel插件,系统没法自动更新classes

3.2 jetty-runer

(1)对于IDEA的jetty-runner插件,须要注意在无web.xml的纯注解开发下,须要将WebApp Folder配置为对应编译后target下的项目目录(在这以前必须使用打包命令mvn package生成target下项目目录)在使用jrebel插件基础上,JSP页面热部署须要从新执行打包命令mvn package。一样classes类热部署需用到JRebel插件,系统没法自动更新classes

(2) 若是使用web.xml配置,那么jetty-runer的WebApp Folder须要设置源码的webapp目录

相关文章
相关标签/搜索