I have a java web service application, i created a .WAR file.
and now i have loaded .WAR file in a folder that is in a root
for example
/mytestdir/mywebapp.WAR
now i want my tomcat5 to run this file that is out of tomcat5 webapps directry.
Please help me how can i run this .WAR that i should be able to access like this
http://www.mysite.com:8080/mywebapp
in .WAR file i have a code that needs to access some root level folders.
this is my first deployment.
You have to create a Tomcat Context.
In order to do so, open TOMCAT_HOME/conf/server.xml and add a Context that will point to the war file location. For example:
<Context path="/MyApplication" docBase="/mytestdir/mywebapp.WAR" reloadable="false" />
Then, restart your Tomcat instance and you're done.
You should change your config.xml
Smth, like this
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/mywebapp" docBase="/mytestdir/mywebapp.WAR">
see docBase attribute
Related
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.
I have a web app set up and running on Tomcat 8 with the project WAR file in the webapps folder in the tomcat directory. If i use any of the following links my project works fine
http://localhost:8066/myWebApp/home/
http://localhost:8066/myWebApp/booking/
http://localhost:8066/myWebApp/contactUs/
i want to set it so the above URL's work but also the following URL's which have /app added after the project name
http://localhost:8066/myWebApp/app/home/
http://localhost:8066/myWebApp/app/booking/
http://localhost:8066/myWebApp/app/contactUs/
i have set the path in the context.xml file as seen below
<Context docBase="myWebApp" path="/app" reloadable="true"> ... <Context>
but this does not work. am i doing this wrong or how can i go about doing this?
EDIT :
I can do this in eclipse by going to the server tab, opening the server and looking in the modules tab, so how do i do this on the Tomcat itself
You maybe use UrlRewriteFilter:
1. Add dependence
2. Change web.xml
3. Set rule in WEB-INF\urlrewrite.xml
or Rewrite.
I would like to have a symbolic link in tomcat's webapps directory that points to a war file at another place in my file system, and I would like that war file to be served as the default webapp. I have pieced together the following solution, but the app is not accessible from the browser.
I have a folder in my home directory ~/tomcat/webapps. The owner is tomcat7. In this folder, I have my war file, myapp-1.0.war.
In my /var/lib/tomcat7/webapps directory, I have a symbolic link:
myapp -> /home/[me]/tomcat/webapps/myapp-1.0.war.
In my /etc/tomcat7/server.xml, I have:
<Context docBase="/var/lib/tomcat7/webapps/myapp" path="" reloadable="true" allowLinking="true"/>
Tomcat starts with no complaints in the logs, but my app is not accessible.
[host]:8080/rest/ returns 404, where it would normally take me to the home page.
I partially want to do this to abstract out the version number from my war file. Any ideas why this is not working, or what I'm doing wrong?
Thanks.
I found the problem. The symlink in the webapps directory needs to have a .war extension. So, instead of:
myapp -> /home/[me]/tomcat/webapps/myapp-1.0.war
It should be:
myapp.war -> /home/[me]/tomcat/webapps/myapp-1.0.war
I was also able to shorten the value of the docBase attribute as below:
<Context docBase="myapp" path="" reloadable="true" allowLinking="true"/>
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?
i am using tomcat.
i have a folder with my website in it called exampleSite
when i go to my website www.example.com i would like the index.html inside exampleSite to load up and not the IndexFile within ROOT.
How would i go about achieving this?
There are two ways of deploying a web application on the filesystem:
Copy your WAR file or your web application's directory (including all of its content) to the $CATALINA_BASE/webapps directory.
Create an XML fragment file with just the Context element for your web application, and place this XML file in $CATALINA_BASE/webapps. The web application itself can then be stored anywhere on your filesystem.
Another way to deploy a web app is by writing a Context XML fragment file and deploying it into the CATALINA_BASE/webapps directory. A context fragment is not a complete XML document, but just one Context element and any subelements that are appropriate for your web application. These files are like Context elements cut out of the server.xml file, hence the name "context fragment."
For example, if we wanted to deploy the WAR file MyWebApp.war along with a realm for accessing parts of that web application, we could use this fragment:
<!--
Context fragment for deploying MyWebApp.war
-->
<Context path="/demo" docBase="webapps/MyWebApp.war"
debug="0" privileged="true">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Context>
Put that in a file called "MyWebApp.xml," and copy it into your CATALINA_BASE/webapps directory.
These context fragments provide a convenient method of deploying web applications; you do not need to edit the server.xml file and, unless you have turned off the default liveDeploy feature, you don't have to restart Tomcat to install a new web application.
Reference
Top Ten Tomcat Configuration Tips