一、配置
默認前兩個是沒有勾選的,應該勾選上:
在Cotext節點中有一個reloadable='true'屬性,將它改為false,可以在修改java文件后不用重啟服務器即可生效,但是不包括新建java文件、添加方法和變量的操作
為了在開發時,讓tomcat能夠自動重新加載,我們修改過的代碼和配置,需要對Tomcat的context.xml文件進行設置。
在<context>標簽中,加上reloadable屬性,並且將值設為true
- <Context reloadable="true">
- <!--注意: reloadable設為true,目的是為了方便開發階段, 它會影響tomcat性能;當在正式部署服務時,需要改成false -->
二、瀏覽文件
Context節點單獨生成的文件:
原來Tomcat安裝目錄下conf/server.xml中的Context節點(勾選第二個選項之后,server.xml中就不存在這個節點了):
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/> <Context docBase="D:\workspace\workspace(eclipse)\Shop\WebContent" path="/Shop" reloadable="true" source="org.eclipse.jst.jee.server:Shop"> <Resources> <PreResources base="D:\workspace\workspace(eclipse)\Shop\build\classes" classLoaderOnly="false" className="org.apache.catalina.webresources.DirResourceSet" internalPath="/" webAppMount="/WEB-INF/classes"/> </Resources> </Context> </Host>
三、原因
1.勾選第一個是為了防止出現警告:
警告: A docBase D:/Tomcat/webapps/Shop inside the host appBase has been specified, and will be ignored
勾選后表示讓tomcat直接使用eclipse中的WebContent下的東西
省去publish到<workspace>.metadata.pluginsorg.eclipse.wst.server.coretmp0webapps
並將tmp0webapps下相關的resources刪除,
同時會修改<workspace>.metadata.pluginsorg.eclipse.wst.server.coreservers.xml中的serveModulesWithoutPublish=true以及tmp0/conf/server.xml中的<Context>配置
2.勾選第二個是為了防止出現警告:
警 告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:strut2demo' did not find a matching property.
[SetPropertiesRule]警告的原因是Tomcat6.0以上的server.xml的context節點中不再支持source屬性了。具體說明如下:
For Tomcat 6, unlike Tomcat 4.x, it is NOT recommended to place <Context> elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat.