tomcat 安装好之后,只需要把你的程序包放到$Tomcat_Home$/webapps下就可以直接使用了。这样会使webapps越来越大就需要设置虚拟目录:
1.单个应用设置(为你的单个项目设置虚拟目录):
在<Host>和</host>之间加上
<Context path="/site" docBase="d:\site" reloadable="true" debug="0">
</Context>
参数:path 表示在浏览器中输入
http://localhost:8080/site
docBase表示你的程序包的物理绝对路径,默认的绝对路径是$Tomcat_Home$/webapps
这样设定了之后会在$tomcat_home$/conf/catalina/localhost目录下生成一个site.xml文件,此文件的内容就是刚才设置的内容。
2.通过前面我们知道了在$tomcat_home$/conf/catalina/localhost目录下会生成相应的配置文件,因此我们可以直接在$tomcat_home$/conf/catalina/localhost目录下写配置文件文件名任意取,最好是跟你的web应用相同便于管理,如site.xml内容同上
<Context path="/site" docBase="d:\site" reloadable="true" debug="0">
</Context>
3.更改整个根目录(为你的所有项目设置虚拟目录):
在$tomcat_home$/conf/server.xml中找到<Host name="localhost" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true">
将appBase的设置成期望的路径(绝对路径)
出现的问题:输入:
http://localhost:8080/没有出现默认的页面
原因当然是更改了路径造成的。解决也很简单了,把文件拷过来,或者再把原来默认的设成虚拟路径。
在调试过程中你也许会遇到这样的错误:
严重: Error starting static Resources
java.lang.IllegalArgumentException: Document base E:\Tomcat 5.0\webapps\balancerd does not exist or is not a readable directory
at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:138)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:3910)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4138)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDeployer.java:903)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216)
at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:256)
at org.apache.commons.digester.Rule.end(Rule.java:276)
at org.apache.commons.digester.Digester.endElement(Digester.java:1058)
at org.apache.catalina.util.CatalinaDigester.endElement(CatalinaDigester.java:76)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:488)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:863)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:483)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
at org.apache.catalina.startup.HostConfig.checkContextLastModified(HostConfig.java:800)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1085)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:327)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.StandardHost.backgroundProcess(StandardHost.java:800)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1619)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1628)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1608)
at java.lang.Thread.run(Thread.java:619)
这是因为在你的$tomcat_home$\conf\Catalina\localhost下对balancerd 这个项目设置虚拟目录的.xml文件指定这个项目的路径不对所造成的把路径改对了该错误消失!