一般的项目都是放到webapps下的,我们这里做一个外部配置
<?xml version='1.0' encoding='utf-8'?>
<Server port="2001" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
maxThreads="3000"
maxPostSize="-1"
maxHttpHeaderSize ="102400"
minSpareThreads="250"
acceptCount="2000"
enableLookups="false"
compression="on"
URIEncoding="UTF-8"
compressionMinSize="2048"
noCompressionUserAgents="gozilla,traviata"
compressableMimeType="text/html,text/xml,text/css,text/plain,text/javascript,application/x-javascript,application/javascript"
/>
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host
name="localhost"
appBase="webapps"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
<Context
path="" //这里放空就行
docBase="/data/rs" //项目路径,可以写绝对,也可以写相对,相对的自己更具自己的项目位置修改
allowLinking="true"
reloadable="false"
privileged="true" >
</Context>
<!-- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" /> -->
</Host>
</Engine>
</Service>
</Server>
如果启动出现问题
java.lang.IllegalStateException:ContainerBase.addChild:start:org.apache.catalina.Life, ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].
StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
atorg.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1090)
at
org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1900)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at
java.util.concurrent.FutureTask.run(FutureTask.java:262)
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina
解决方法:
更改tomcat配置文件catalina.properties。
tomcat.util.scan.DefaultJarScanner.jarsToSkip= 值后面加",*"
启动界面乱码
修改日志配置文件logging.properties中的控制台编码
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
java.util.logging.ConsoleHandler.encoding = GBK