Java 应用程序未加载到 Tomcat 7 服务器上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18666269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 09:58:51  来源:igfitidea点击:

Application not loading on Tomcat 7 server

javaeclipsetomcatvaadin

提问by abden003

I am running an application on my Tomcat 7 server. The server loads and runs but, when I enter http://localhost:8080/ApplicationTestI get the following error:

我正在我的 Tomcat 7 服务器上运行一个应用程序。服务器加载并运行,但是,当我输入时,出现http://localhost:8080/ApplicationTest以下错误:

HTTP Status 404 - /ApplicationTest

type Status report

message /ApplicationTest

description The requested resource is not available.

Apache Tomcat/7.0.42

I have switched location in my properties and in Tomcat Server 7 settings under Server Location I have changed it to "Use Tomcat Installations". But it is still not working, I even tried to reinstall the server. I am using Eclipse Kepler and Tomcat 7, and running a vaadin web application. I do not get any errors in my tomcat logs, it is below:

我已经在我的属性和服务器位置下的 Tomcat Server 7 设置中切换了位置,我已将其更改为“使用 Tomcat 安装”。但它仍然无法正常工作,我什至尝试重新安装服务器。我正在使用 Eclipse Kepler 和 Tomcat 7,并运行 vaadin Web 应用程序。我的 tomcat 日志中没有任何错误,如下所示:

Sep 06, 2013 3:32:27 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: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\ThinkPad\Bluetooth Software\;C:\Program Files\ThinkPad\Bluetooth Software\syswow64;;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK.0\bin\x64;C:\Program Files\Common Files\Lenovo;C:\Program Files (x86)\Windows Live\Shared;C:\SWTOOLS\ReadyApps;C:\Program Files (x86)\Symantec\VIP Access Client\;C:\Program Files (x86)\Common Files\Lenovo;C:\Program Files (x86)\Java\jre7\bin;C:\Program Files\Java\jre7\bin;C:\MinGW\bin;C:\Program Files (x86)\Gow\bin;C:\Program Files (x86)\WinSCP\;C:\Program Files (x86)\Notepad++\;.
Sep 06, 2013 3:32:27 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:TweetApp' did not find a matching property.
Sep 06, 2013 3:32:27 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Sep 06, 2013 3:32:27 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 06, 2013 3:32:27 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 722 ms
Sep 06, 2013 3:32:27 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 06, 2013 3:32:27 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
Sep 06, 2013 3:32:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\wa7sh\Programs\apache-tomcat-7.0.42\webapps\docs
Sep 06, 2013 3:32:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\wa7sh\Programs\apache-tomcat-7.0.42\webapps\examples
Sep 06, 2013 3:32:29 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Sep 06, 2013 3:32:29 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Sep 06, 2013 3:32:29 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@2e901f36')
Sep 06, 2013 3:32:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\wa7sh\Programs\apache-tomcat-7.0.42\webapps\host-manager
Sep 06, 2013 3:32:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\wa7sh\Programs\apache-tomcat-7.0.42\webapps\manager
Sep 06, 2013 3:32:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\wa7sh\Programs\apache-tomcat-7.0.42\webapps\ROOT
Sep 06, 2013 3:32:29 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Sep 06, 2013 3:32:29 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 06, 2013 3:32:29 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1788 ms

So my question is how do I fix this problem, how do i run my application on my tomcat 7 server? Below is my server.xml if that helps:

所以我的问题是如何解决这个问题,如何在我的 tomcat 7 服务器上运行我的应用程序?如果有帮助,下面是我的 server.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
--><!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 --><Server port="8005" shutdown="SHUTDOWN">
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener"/>
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the JSSE configuration, when using APR, the
         connector should be using the OpenSSL style configuration
         described in the APR documentation -->
    <!--
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine defaultHost="localhost" name="Catalina">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>

      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>

      <Context docBase="TweetApp" path="/TweetApp" reloadable="true" source="org.eclipse.jst.jee.server:TweetApp"/></Host>
    </Engine>
  </Service>
</Server>

Below is my servlet-mapping in my web.xml

下面是我的 web.xml 中的 servlet 映射

<!-- ================ Built In Servlet Mappings
========================= -->


  <!-- The servlet mappings for the built in servlets defined above.  Note  -->   <!-- that, by default, the CGI and SSI servlets are *not* mapped.  You    -->   <!-- must uncomment these mappings (or add them to your application's own -->   <!-- web.xml deployment descriptor) to enable these services              -->

    <!-- The mapping for the default servlet -->
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- The mappings for the JSP servlet -->
    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.jspx</url-pattern>
    </servlet-mapping>

    <!-- The mapping for the SSI servlet --> <!--
    <servlet-mapping>
        <servlet-name>ssi</servlet-name>
        <url-pattern>*.shtml</url-pattern>
    </servlet-mapping>
-->

    <!-- The mapping for the CGI Gateway servlet -->

<!--
    <servlet-mapping>
        <servlet-name>cgi</servlet-name>
        <url-pattern>/cgi-bin/*</url-pattern>
    </servlet-mapping>
-->

采纳答案by abden003

I found out what was wrong with the application it seems that my server was working it was my application that was having the problem. I am using the newest version of eclipse (kepler) and whenever I create new vaadin web application it defaults the configuration to "Vaadin 7, Java 6, Servlet 3.0", and this configuration for some reason did not auto create a web.xml file in the WEB-INF Folder. To fix this I chose "Vaadin 7, Java 6, Servlet 2.4", which auto created the web.xml for me. There is probably a better solution, but as of now this worked. If someone posts a better solution I will choose their answer.

我发现应用程序有什么问题,似乎我的服务器正在工作,是我的应用程序出现问题。我正在使用最新版本的 eclipse (kepler),每当我创建新的 vaadin Web 应用程序时,它都会将配置默认为“Vaadin 7、Java 6、Servlet 3.0”,并且由于某种原因,此配置没有自动创建 web.xml 文件在 WEB-INF 文件夹中。为了解决这个问题,我选择了“Vaadin 7, Java 6, Servlet 2.4”,它自动为我创建了 web.xml。可能有更好的解决方案,但截至目前,这是有效的。如果有人发布更好的解决方案,我会选择他们的答案。

回答by Sotirios Delimanolis

Assume your application is called TweetApp. Let's do some cleanup.

假设您的应用程序名为TweetApp。让我们做一些清理工作。

  1. Right-click your server and Deleteit.
  2. Create a new Tomcat server instance and add TweetAppapplication to it.
  3. In the Project Explorer, select the Serversfolder, open your instance, and open server.xml.
  4. Towards the bottom, there should be a <Context>element for it. Use the pathattribute to build a URL.
  5. Start the server.
  1. 右键单击您的服务器和Delete它。
  2. 创建一个新的 Tomcat 服务器实例并向其添加TweetApp应用程序。
  3. 在 Project Explorer 中,选择Servers文件夹,打开您的实例,然后打开server.xml.
  4. 在底部,应该有一个<Context>元素。使用该path属性构建一个URL.
  5. 启动服务器。

For example, if pathis /TweetApp, access your application at localhost:8080/TweetApp/.

例如,如果path/TweetApp,请访问您的应用程序localhost:8080/TweetApp/

If you want to make sure the application is started, I would recommend you register a ServletContextListenerand put a log statements in its contextInitialized()method and make sure its printed when you restart the server.

如果您想确保应用程序已启动,我建议您注册一个ServletContextListener并在其contextInitialized()方法中放置一个日志语句,并确保在您重新启动服务器时打印它。

回答by akashsharma3030

I faced the same problem I did below and it worked. 1)I refreshed my project in the eclipse and then added the war file in the tomcat and then it worked.

我遇到了我在下面做的同样的问题并且它起作用了。1)我在eclipse中刷新了我的项目,然后在tomcat中添加了war文件,然后就可以了。