Reputation: 21616
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
.
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 "%r" %s %b" />
<Context docBase="app-renderer" path="/" reloadable="true" />
</Host>
the problem was about the ROOT
directory in webapps
, after removing now I could have the app as root.
Upvotes: 5
Views: 9130
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
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 "%r" %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
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