tokhi
tokhi

Reputation: 21616

servlet context to tomcat 7 root

Whats the best approach to place servlet context to tomcat 7 root? I have tried this post here but didn't work for me; i'm using Apache Tomcat/7.0.42.

P.S: I don't want to rename the project name as ROOT.war.

Update

I have placed the context tag as explained in one of the answers, but still getting the tomcat home page as root:

<Host name="localhost"  appBase="webapps"               
   <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" />    
   <Context docBase="app-renderer" path="/" reloadable="true" />
 </Host>

Update 2

the problem was about the ROOT directory in webapps, after removing now I could have the app as root.

Upvotes: 5

Views: 9130

Answers (3)

tokhi
tokhi

Reputation: 21616

Without changing the .war file to ROOT follow below steps:

1. Create a file named ROOT.xml under the tomcat/conf/Catalina/localhost/

2. paste below code into the ROOT.xml file:

<Context
  docBase="/home/user/YOUR_PROJECT/target/YOUR_PROJECT.war"
  path=""
  reloadable="true"
/>

Now you can access your project in tomcat root.

To have a clean project remove tomcat/webapps/ROOT directory.

Upvotes: 0

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279990

In your Tomcat's conf/server.xml file, you'll typically have an entry

<Context docBase="yourApp" path="/somePath" reloadable="true" source="someSource"/>

for your application.

Change the path to /

<Context docBase="yourApp" path="/" reloadable="true" source="someSource"/>

Add this in the Host entry. For example

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

    <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" />
<Context docBase="yourApp" path="/" reloadable="true" />
</Host>

where the docBase attribute is the name of your app as it appears in the webapps folder. The docs explain the meaning of each attribute.

Upvotes: 5

Olaf Kock
Olaf Kock

Reputation: 48067

check the context documentation. You're looking for the docBase attribute for your webapp's path and the path attribute for the root context, e.g. leave it empty as described in the attribute's documentation.

Upvotes: 0

Related Questions