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
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.
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.
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.