Servlet context for tomcat 7 root

What is the best approach for hosting servlet context in tomcat 7 root? I tried this post here , but did not work for me; I am using Apache Tomcat/7.0.42 .

PS: I do not want to rename the project name as ROOT.war .

Update

I put the context tag as described in one of the answers, but still get the tomcat homepage with root privileges:

 <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 in the ROOT directory in webapps , after uninstalling now I could use the application as root.

+4
source share
3 answers

In your Tomcat conf/server.xml file, you will usually 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 to the Host entry. for instance

 <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 application that appears in the webapps folder. Documents explain the meaning of each attribute.

+5
source

check context documentation . You are looking for the docBase attribute for your webapp path and the path attribute for the root context, for example. leave it blank as described in the attribute documentation.

0
source

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

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

2. Paste the code below 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 the root of tomcat.

To delete a clean project, delete the tomcat/webapps/ROOT directory.

0
source

Source: https://habr.com/ru/post/1499807/


All Articles