您的位置:首页 > 运维架构 > Tomcat

jdk配置正确但是tomcat服务器启动时一闪而过

2016-01-14 20:23 573 查看
今天看了些tomcat的一些东西,在启动tomcat的时候出现了一些问题,查了网上的一些解决方案,有的说是没配置JAVA_HOME,有的说是因为内存溢出,按照这些方法都试了下,发现并不能解决问题,还是内容都显示出后服务器就关闭了。后来想起来看下日志,日志内容如下:

一月 14, 2016 7:01:47 下午 org.apache.catalina.startup.Catalina start

严重: The required Server component failed to start so Tomcat is unable to start.

org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)

Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more

Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more

Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 11 more

这些日志并没有很清晰的说明问题,后来就想起来重装系统前,自己在server.xml中配置了虚拟目录(这种方法今天看完一个博客JavaWeb学习总结(二)——Tomcat服务器学习和使用(一)后发现是不明智的),重装系统后,换了用户名,以前映射的目录在C盘的某个带用户名的目录下,果断找到那个文件,把那些配置删了,再重新启动,就OK了。

下面是javaweb那个博客的一些内容,原文转载:

1、端口修改

Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件。如果想修改Tomcat服务器的启动端口,则可以在server.xml配置文件中的Connector节点进行的端口修改

例如:将Tomcat服务器的启动端口由默认的8080改成8081端口

Tomcat服务器启动端口默认配置

1 <Connector port="8080" protocol="HTTP/1.1"
2                connectionTimeout="20000"
3                redirectPort="8443" />


将Tomcat服务器启动端口修改成8081端口

1 <Connector port="8081" protocol="HTTP/1.1"
2                connectionTimeout="20000"
3                redirectPort="8443" />


2、


Tomcat服务器虚拟目录的映射方式


虚拟目录的映射方式一:在server.xml文件的host元素中配置

找到server.xml文件的host元素,如下图所示:

  

  在<Host></Host>这对标签加上<Context path="/JavaWebApp"docBase="F:\JavaWebDemoProject" />即可将在F盘下的JavaWebDemoProject这个JavaWeb应用映射到JavaWebApp这个虚拟目录上,JavaWebApp这个虚拟目录是由Tomcat服务器管理的,JavaWebApp是一个硬盘上不存在的目录,是我们自己随便写的一个目录,也就是虚拟的一个目录,所以称之为"虚拟目录",代码如下:

1 <Host name="localhost"  appBase="webapps"
2              unpackWARs="true" autoDeploy="true"
3              xmlValidation="false" xmlNamespaceAware="false">
4
5          <Context path="/JavaWebApp" docBase="F:\JavaWebDemoProject" />
6  </Host>


  其中,Context表示上下文,代表的就是一个JavaWeb应用,Context元素有两个属性,

  Ⅰ.path:用来配置虚似目录,必须以"/"开头。

  Ⅱ.docBase:配置此虚似目录对应着硬盘上的Web应用所在目录。

  使用浏览器访问"/JavaWebApp"这个虚拟目录下的1.jsp这个web资源,访问结果如下:

  

  1.jsp可以正常访问,这说明我们已经成功地将将在F盘下的JavaWebDemoProject这个JavaWeb应用映射到JavaWebApp这个虚拟目录上了,访问"/JavaWebApp/1.jsp"就相当于访问"F:\JavaWebDemoProject\1.jsp"

  注意:在Tomcat6之后中,不再建议在server.xml文件中使用配置context元素的方式来添加虚拟目录的映射,因为每次修改server.xml文件后,Tomcat服务器就必须要重新启动后才能重新加载server.xml文件。在Tomcat服务器的文档http://localhost:8080/docs/config/context.html中有这样的说明:

  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.

Individual Context elements may be explicitly defined:
In an individual file at 
/META-INF/context.xml
 inside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to
$CATALINA_BASE/conf/[enginename]/[hostname]/
 and
renamed to application's base file name plus a ".xml" extension.
In individual files (with a ".xml" extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/
 directory. The context path and version will be derived from the base name of the file (the file name less the .xml
extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.
Inside a Host element in the main 
conf/server.xml
.


虚拟目录的映射方式二:让tomcat服务器自动映射

   tomcat服务器会自动管理webapps目录下的所有web应用,并把它映射成虚似目录。换句话说,tomcat服务器webapps目录中的web应用,外界可以直接访问。

  例如:把F盘下的JavaWebDemoProject这个JavaWeb应用直接copy到tomcat服务器webapps目录中,如下图所示:

  

  此时Tomcat服务器就会自动为JavaWebDemoProject这个JavaWeb应用映射一个同名的虚拟目录"/JavaWebDemoProject",然后就可以使用浏览器访问这个JavaWeb应用的资源了,如下图所示:

  


虚拟目录的映射方式三

  参考Tomcat服务器文档:

  In individual files (with a ".xml" extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/
 directory. The context path and version will be derived from the base name of the file (the file
name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.

  意思就是:在tomcat服务器的\conf\Catalina\localhost目录下添加一个以xml作为扩展名的文件,xml文件的名字可以任意取,比如下面的aa.xml,注意这一句话"The context path and version will be derived from the base name of the file",这一句话的意思翻译过来就是"context元素的path属性源自于是这个xml文件的名字",上面提到过,Context元素的path属性是用来配置虚似目录的名称的,所以虚似目录的名称就是这个xml文件的名称。

  $CATALINA_BASE
指的就是tomcat服务器根目录,
[enginename]
指的是Tomcat服务器使用的引擎名称,Tomcat使用的引擎是Catalina

  

  在aa.xml文件中添加Context[/b]元素映射JavaWeb应用,代码如下:

1 <Context docBase="F:\JavaWebDemoProject" />


  注意:在Context元素中并没有指明path属性来设置虚拟目录的名称,那么"F:\JavaWebDemoProject"映射的虚拟目录名称是神马呢,就是当前正在编辑的这个xml文件的名称aa。

  

  使用这种方式映射虚拟目录的最大好处是修改了配置文件后不用重启Tomcat服务器,比如将aa.xml修改成bb.xml,Tomcat服务器会自动Undeploying context [/aa],然后自动信息: Deploying configuration descriptor D:\apache-tomcat-7.0.53\conf\Catalina\localhost\bb.xml

  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息