<!--首先配置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
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/。
IDEA配置tomcat比較簡單,若是須要熱部署jsp頁面須要 on 'Update' action設置爲Update classes and resources。classes類熱部署需用到JRebel插件,系統沒法自動更新classes
(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目錄