5

Every application deployed on my Tomcat returns status code 404 on every request I make. I've tried several projects, helloworlds or skeletons and every project behaves the same as others:

enter image description here


Some of the projects I've used:

https://github.com/mwarman/skeleton-ws-spring-boot

https://spring.io/guides/gs/rest-service/ (I can run it with mvn spring-boot:run but it's not working as deployed to Tomcat)

https://github.com/shagstrom/spring-mvc-hibernate-skeleton


I'm using the newest Tomcat8 (8.0.27), Oracle JDK 8. I've also tried Tomcat7 with OpenJDK 7. Used Tomcats are running on MAC and Debian. I've build apps via mvn and via Intellij Idea.

Tomcats are clean, no configs are changed (except adding manager-gui user).

Since I've tried many different projects, I don't believe the problem is in the code. Is it in Tomcat's config? How can I get it to work?

EDIT: server.xml code:

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />

  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- 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 name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">

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

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

    <Engine name="Catalina" defaultHost="localhost">

      <!-- 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 name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="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"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>
Jakub Turcovsky
  • 2,096
  • 4
  • 30
  • 41
  • 1
    How are you deploying your projects in tomcat? Are you sure they're being deployed by checking the logs? – Luiggi Mendoza Oct 11 '15 at 21:48
  • Are the applications listing in the Tomcat Manager, and are they started? Is the HOME page working (`http://localhost:8080/`)? – Andreas Oct 11 '15 at 21:50
  • @LuiggiMendoza I'm deploying it via Idea or via manager. From logs: "Artifact is deployed successfully" confirms that deploy was successful. – Jakub Turcovsky Oct 11 '15 at 22:02
  • @Andreas HOME page is working, my applications listed in manager are running. – Jakub Turcovsky Oct 11 '15 at 22:04
  • @2rec are applications in your tomcat's webapps folder ? Can you post your conf/server.xml ? – Erwan C. Oct 12 '15 at 08:36
  • @ErwanC. Yes, applications are in webapps folder. Please see my server.xml file in my edited question above. It's a default file. – Jakub Turcovsky Oct 12 '15 at 13:30
  • This question seems really similiar to another question. So, try this answer: http://stackoverflow.com/a/28089714/946409 – Pitel Oct 14 '15 at 14:08
  • Most of the spring-boot examples I've seen run embedded tomcat. Check out this post which has the same question. [spring-boot-war-without-tomcat-embedded](http://stackoverflow.com/questions/25991789/spring-boot-war-without-tomcat-embedded) – caburse Oct 12 '15 at 14:56
  • The spring boot project was only one of many I've used, but I'll try your solution on it and let you know. – Jakub Turcovsky Oct 12 '15 at 16:38
  • So no, this is not working. :-/ I've had the war packaging option turned on before, but the exclusion of embedded tomcat didn't help. – Jakub Turcovsky Oct 12 '15 at 17:31
  • A few questions: 1. After building https://github.com/shagstrom/spring-mvc-hibernate-skeleton with Maven, do you end up with `skeleton-1.0.0.war`? 2. If so, what are the results on executing `jar tf skeleton-1.0.0.war`? 3. If you copy this WAR file to `apache-tomcat-8.0.27/webapps/` do you see a `skeleton-1.0.0` directory being created by Tomcat? – Will Hogan Oct 18 '15 at 04:27

3 Answers3

0

If you installed tomcat successfully, you may have seen tomcat main page from browser http://localhost:8080/ URL. (Otherwise, you need to check tomcat installation first.)

I guess you may have built jar by fallowing above sites that you mentioned. I am wondering whether you applied the jar into your tomcat or not because you mentioned same result from any other projects. You need to apply jar or war into your tomcat in order to apply java program.

Here are links that I wish they might be helpful to you.

Packaging war : How to make war file in Eclipse

Tomcat - war file deployment : https://www.youtube.com/watch?v=9X9DA8oVodk

Community
  • 1
  • 1
HsYoo
  • 76
  • 3
  • Thanks for the reply but I am able to create and deploy war from these projects, also Tomcat's index page and manager are ok. Deploy is successful and project is running. – Jakub Turcovsky Oct 16 '15 at 17:05
0

If tomcat returns 404 response, you have to check those points:

  • check if your deploy was correct
  • check if war bootstrap and its ServletContext initialization has no errors
  • check if the resource your invoking was successfully exposed.

To test these issues you have to expose:

  • static resource test
  • web service resource test

in this way you can exclude the pitfalls you can meet during application deploy

banan3'14
  • 3,810
  • 3
  • 24
  • 47
0

status code 404

  <!-- 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 name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="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"
           prefix="localhost_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>
</Engine>
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 28 '23 at 18:06