我是Tomcat和Eclipse的新手,但几天来一直在寻找解决方案。我已经安装了Tomcat v7.0并且可以从终端启动/停止它,但是我不能让它从Eclipse工作。我正在http://www.vogella.de/articles/EclipseWTP/article.html#jspservlets上学习本教程,但是当我尝试运行我的servlet时,我收到警告:“localhost上的服务器Tomcat v7.0服务器无法启动”,控制台输出为:
Feb 18, 2012 7:05:54 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Feb 18, 2012 7:05:54 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:de.vogella.wtp.filecounter' did not find a matching property.
Feb 18, 2012 7:05:54 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Feb 18, 2012 7:05:54 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Feb 18, 2012 7:05:54 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1046 ms
Feb 18, 2012 7:05:54 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Feb 18, 2012 7:05:54 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.25
Feb 18, 2012 7:05:55 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Feb 18, 2012 7:05:55 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Feb 18, 2012 7:05:55 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 654 ms
Feb 18, 2012 7:05:55 PM org.apache.catalina.core.StandardServer await
SEVERE: StandardServer.await: create[localhost:8005]:
java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)
at java.net.ServerSocket.bind(ServerSocket.java:328)
at java.net.ServerSocket.<init>(ServerSocket.java:194)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:422)
at org.apache.catalina.startup.Catalina.await(Catalina.java:728)
at org.apache.catalina.startup.Catalina.start(Catalina.java:674)
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.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Feb 18, 2012 7:05:55 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
Feb 18, 2012 7:05:55 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
Feb 18, 2012 7:05:55 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Feb 18, 2012 7:05:55 PM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8080"]
Feb 18, 2012 7:05:55 PM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
Feb 18, 2012 7:05:55 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8080"]
Feb 18, 2012 7:05:55 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]
在我尝试运行Tomcat之前,netstat没有显示正在使用的端口8080,8005或8009,所以这似乎不是问题所在。知道出了什么问题吗?
答案 0 :(得分:4)
当您安装Tomcat时,它似乎决定在服务模式下运行,并且必须在启动系统时运行。因此,当您通过eclipse启动tomcat时出现错误。使用server.xml中的其他端口可能无法解决您的问题。我猜是tomcat的另一个实例已经在运行。可以在启动之前检查另一个tomcat实例的taskmanager是否正在运行它来自日食? 你也可以发布netstat run的结果吗?
答案 1 :(得分:0)
第1步:转到C:\ Windows \ System32 \ drivers \ etc
第2步:
找到主机文件并使用带有管理员模式的记事本打开它
第3步:
用127.0.0.1替换本地主机IP
例如
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
# ::1 localhost
第4步:
保存该文件并运行服务器
答案 2 :(得分:-2)
更改Tomcat端口设置:
似乎Tomcat已经集成在Eclipse中。因此,Eclipse中应该有一个名为“ Servers ”的项目,您可以找到Tomcat配置节点。更改server.xml
中的端口属性。当然,该插件提供了许多与Tomcat集成的方法,但基本的想法是更改server.xml
。