I have a web app run in tomcat 8. I want to change the access URL.
I use the tomcat default manager app for example.
With the default config, the manager app locates on webapps folder. The manager means the app name. But if I don't want to expose the app name and want the app to be accessed by localhost:8080/tomcat-manager, what should I do?
According the official documents, I modified the context.xml in manager/META-INF folder. My context.xml is as below:
<Context path="/tomcat-manager" docBase="manager"> </Context>
Then I think I can access the manager app by localhost:8080/tomcat-manager, but it doesn't work.
So I want to know how can I do this?
Re-name the folder called manager to tomcat-manager and you are done.
Read the documentation for more information.
UPDATE
You should never specify path in your META-INF/context.xml file: the path will be determined from the name of the WAR file. Also, never specify the docBase in META-INF/context.xml, because the docBase is already known (the META-INF/context.xml is already relative to something: the docBase).
That said, if you use an external context.xml file (e.g. in $CATALINA_BASE/conf/[engine]/[host]/[appname].xml then you must specify a docBase pointing to your WAR file (or exploded WAR directory). You will still never use path in that file.
Related
I developed a web application and deployed in tomcat6. Actually, this web application has number of property files. Now, we placed all property files in WEB-INF/classes directory and So, the web app is running perfectly as this is default class path. Now, I want to keep all property files in a separate directory webapps/web_application/config and add this directory to tomcat class path. So that I don't have to change any java file for specifying new path of property files. I googled it a lot. But, every one is suggesting to place all property files in tomcat_home/XXXX and add this path in tomcat_home/conf/catalina.properties file attribute shared.loader="" . But, I do not want to do like this as these property files are my application specific. Is there any way to add webapps/web_application/config directory to classpath . Appreciate any help.
You can use a Manifest Class-Path entry to modify the web-app's class path.
Note that I would not use webapps/web_application/config because this location would be accessible from a web browser.
I want to define a context in my tomcat server on openshift cloud. I have done it successfully in my local tomcat server but I don't know how to do it on openshift.
I did it in local by adding :
<Context docBase="E:/captcha" path="/test/captcha"></Context>
to my tomcat's server.xml file. But in openshift I don't know how to define the docbase attribute.
Thanks for any useful response!
You shouldn't really be using <Context> in server.xml these days.
Instead, put your WAR file in the proper place. If you must use an XML descriptor, take the META-INF/context.xml file (which you should have!) and put it into CATALINA_BASE/conf/[engine]/[host]/[appname].xml and Tomcat will deploy it.
Unfortunately, if you can't use WAR-deployment, then you'll still have to figure out what the docBase should be. Where is your WAR file?
This question already has answers here:
Deploy war on Tomcat without the war name in the URL
(4 answers)
Closed 9 years ago.
I 've just created war file of my web project (JSP/Servlets).
Project name: TestApp
when I deply it in Tomcat 7, I run itlike that:
localhost:8080/TestApp/ or www.maypage.com/testApp/
ok, everything works, but I need to run it without project name, like that:
localhost:8080 and on hosting www.maypage.com
How can I do that?
thank you.
And I'm fining jsp/servlet hosting, which have that configuration option. do you know hosting like that?
In order to access your application without using the application name, you need to deploy it as the root application. There are multiple ways to achieve it and the related answer describes it pretty well.
Setting default application in tomcat 7
Content copied from the above link:
First Method:
first shutdown your tomcat [from the bin directory (sh shutdown.sh)]
then you must delete all the content of your tomcat webapps folder (rm
-fr *) then rename your WAR file to ROOT.war finally start your tomcat [from the bin directory (sh startup.sh)]
Second Method:
leave your war file in CATALINA_BASE/webapps, under its original name
- turn off autoDeploy and deployOnStartup in your Host element in the server.xml file. explicitly define all application Contexts in
server.xml, specifying both path and docBase. You must do this,
because you have disabled all the Tomcat auto-deploy mechanisms, and
Tomcat will not deploy your applications anymore unless it finds their
Context in the server.xml.
Note:
that this last method also implies that in order to make any change to
any application, you will have to stop and restart Tomcat.
Third Method:
Place your war file outside of CATALINA_BASE/webapps (it must be
outside to prevent double deployment). - Place a context file named
ROOT.xml in CATALINA_BASE/conf//. The single element in this context
file MUST have a docBase attribute pointing to the location of your
war file. The path element should not be set - it is derived from the
name of the .xml file, in this case ROOT.xml. See the Context
Container above for details.
The tomcat 6.0 document at http://tomcat.apache.org/tomcat-6.0-doc/config/context.html says:
Only if a context file does not exist for the application in the $CATALINA_BASE/conf/[enginename]/[hostname]/, in an individual file at /META-INF/context.xml inside the application files. If the web application is packaged as a WAR then /META-INF/context.xml will be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer /META-INF/context.xml is placed in the host's appBase.
However I noticed that if you put new war file in webapp directory, the context.xml in META-INF directory replaces context.xml in $CATALINA_BASE/conf/[enginename]/[hostname].
Is there any configuration which makes sure that context.xml in $CATALINA_BASE/conf/[enginename]/[hostname]/ is not overwritten whenever new war file is deployed.
Edit: I am using autodeploy="true" From the comment of JoseK, I understand when tomcat sees new war file, it undeploys old application (leading to deletion of context file) and deploys the the new war file (leading to creation of new war file). In that case the above information from tomcat document is not relavant. The new question can there be any situation where the above thing can happen?
I agree that the documentation is misleading. Normally, this behaviour is actually welcomed since when you deploy a new version of your application, you want to have your updated context.xml file deployed as well. If you plan on editing your context.xml file manually on your production server, I suggest skip it altogether and copy its content to conf/server.xml file.
A quick patch/solution to your problem (wouldn't do it myself) is to mark the context.xml file as readonly after it has been deployed and updated the first time. This way Tomcat cannot delete/update it.
If you want to avoid overwriting of 'context.xml', you could go to Tomcat Manager url
and then uninstall the previous app and install the new war/ear.
This way you have more control on the installation process.
I have this folder under Tomcat webapps/mysite which is where all my JSPs and other things are located. To access this folder I go to http://blah.com/mysite and it works just fine. However (because of stylesheets and images statically connected to the root /) I have to make it so that when I go to http://blah.com/ it will load the stuff inside webapps/mysite.
I've tried many different things including contexts and setting the absolute path in server.xml... nothing seems to work, whenever I go to http://blah.com/ it still tries to load the ROOT folder... what's happening here?
The solution I use is to set this in your Tomcat server.xml
Add a <Context> element within the <Host> like below which sets your mysite as the default web app. Note the empty path="" which makes it the default.
<Context docBase="mysite" path="" />
Attributes of Context Container from the Tomcat docs:
docBase You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory
of the owning Host.
path All of the context paths within a particular Host must be unique. If you specify a context path of an empty string (""), you are
defining the default web application for this Host, which will process
all requests not assigned to other Contexts.
See others who have had similar question and the similar answer here, here and here
See also Apache Tomcat Configuration Reference - Context
There are a number of ways to make an application the root application. The simplest way is to just replace the contents of webapps/ROOT with the contents of your web application.
For other solutions, please see the following website:
http://wiki.apache.org/tomcat/HowTo#How_do_I_make_my_web_application_be_the_Tomcat_default_application_.3F
https://stackoverflow.com/users/1123501/george-siggouroglou 's awnser works but lacks a step.
delete ROOT and all items
copy the war to webapps as ROOT.war
Without the deletion, it may not work. Tested with docker.
You can rename your war from something.war == to ==> ROOT.war.
So, tomcat will unpack the war and will create the folder ROOT for it.
It is a trick that is working on tomcat 8 also.