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"/>
Related
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 need to run my Java application on cPanel. I have successfully installed Tomcat,
I can run my application by copying war file into my www folder but the problem is that it shows the Project name (war file name) in the address, I need to know how to remove that, so users can access www.example.com rather than www.example.com/MyProject/index.jsp?
According to one cpanel hosting service command prompt access is generally turned off for cpanel for security reasons and you have to ask for it specifically. If you have this access you can login and run the unzip command (after uploading the war file using FileZilla or similar).
According to cpanel if you don't have command prompt access, you can upload the war to your public_html directory, but before doing this you need to change the apache config and add a "JkMount" for this (see the one with "appname" below).
<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /*.do ajp13
JkMount /appname/* ajp13
</IfModule>
Except of course you put "your app name" instead of appname. This change will instruct apache to redirect calls to the top-level url (ie mydomain.com/appname) to your Tomcat instance (ie mydomain.com:8080/appname). After you have uploaded the war and changed the config, you have to restart apache.
But we said we didn't have ssh access, so how do we modify that file. according to this forum we can edit the /home/username/public_html/.htaccess or just /public_html/.htaccess and add these lines:
SetHandler jakarta-servlet
SetEnv JK_WORKER_NAME ajp13
Now, apache will re-direct to tomcat for mydomain.com/appname instead of mydomain.com:8080/appname. How do we get it to work from just mydomain.com? I simply don't know the answer to this. As far as I know using the usual trick of changing the war file to ROOT.war does not work in cpanel.
You will have to fix the entries at /usr/local/jakarta/tomcat/conf/server.xml Some time back after lot of tweaking I used this and it worked:
<Host name="domain.com" appBase="/home/username/public_html" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" reloadable="true">
<Alias>www.domain.com</Alias>
<Context path="" reloadable="true" docBase="/home/username/public_html" debug="1" privileged="true" autoDeploy="true" liveDeploy="true" />
<Context path="/manager" debug="0" privileged="true" docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>
</Host>
A name of a war file has nothing to do how the project is presented by the container - it's just a matter of configuration and by default containers presents context path as a file name.
And using ROOT.war is just a silly trick, read about Context configuration in Tomcat (I have assumed you are using Tomcat)
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
There's several ways to set the application root context in tomcat. All of them described in the documentation of the server. Here's another one
Modify tomcat_home\conf\server.xml. Under the <Host tag put
<Context path="" docBase="yourappname" debug="0" reloadable="true" />
where you put yourappname.war in the webapps folder reflecting appBase attribute of the <Host tag.
Save, restart the server.
If you can't edit server.xml , Then you can delete ROOT.war and rename your war file to ROOT.war or just extract your .war file to a directory name ROOT.
Next time you open your site ex - www.example.com , index.jsp will be shown to you.
I have done the same for my site at Openshift which provides free PAAS service
they just need to unzip the .war archive in shell. See:
How to deploy a .WAR application - Ubiquity Web Hosting Wiki
We have over 100 users that have used these instructions and it works great. If you deployed Tomcat using EasyApache and have it setup as cPanel has designed, that should be about it. That was derived from:
http://twiki.cpanel.net/twiki/pub/Al...s08/Tomcat.pdf
http://forums.cpanel.net/f42/how-auto-deploy-war-cpanel-server-55096.html
I have copied the sample.war file in webapps directory of tomcat.
I can acess localhost:8080.
deploying of wars is automatic by default -i have checked my webapps folder for an extracted folder "sample"
but it is not extracted.why the war file is doesn't extracted.please give me solution for this.
Delete that war file from webapps/ directory. Then open link http://localhost:8080/ in your web browser. Click Tomcat Manager then enter user name and password. In next page you can see one option called "WAR file to deploy". Select your war file from there and click "deploy" button.
If you want auto deployment when you copy files to webapp/ directory. Then make sure that you server.xml file contains the following values:
autoDeploy="true"
unpackWARs="true"
Just search these values in your server.xml file and edit values as shown above
For more info see Deploy A New Application from a Local Path.
In general this happens when you have 2 Tomcats. If CATALINA_HOME is referring to Tomcat-A and you are trying to run Tomcat-B from Tomcat-B/bin/startup.bat. It will run Tomcat-A. Hence your war which you are trying to deploy in Tomcat-B will not be extracted as Tomcat-A is running in actual.
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
Tomcat is installed at C:\tomcat7\ but I want to deploy .war files in C:\myapp\xyz. For example, I might have C:\myapps\xyz\MyApp.war and I should be able to reach it with the path http://localhost:8080/MyApp.
I tried appending this to the bottom of c:\tomcat7\conf\server.xml
<Host
name="myapp"
appBase="c:\myapps\xyz\"
unpackWARs="true"
autoDeploy="true">
</Host>
</Engine>
</Service>
</Server>
This doesn't seem to work though as I don't see MyApp listed in the management console and I am not able to hit the URL. What else do I need to do?
Also, slightly unrelated but, how can I not have the name of the war file tied to the context name or URL path? For example, I want http://localhost/coolName to point to C:\myapps\xyz\MyApp.war.
Unfortunately the way Tomcat loads a war by filename is a tricky limitation.
I use a slightly different & OS-specific approach: "Symbolic Links". This isn't a direct answer, but may help you out anyway.
Caveats:
I use Linux, but this is
also possible in Windows Vista &
Windows 7.
using wars is still awkward using this method.
Wars are zip files, so best to
unzip your war into a
version-named folder.
Solution:
Create symbolic links (like a Virtual Directory on the filesystem) from your myapps folder into the webapps folder.
This enables "coolName",
"coolName-v2", etc.
each webapp
could potentially be kept in
different places in the filesystem
You can easily 'roll back' or 'upgrade' just by removing and re-adding symbolic links to different targets (make sure to "stop" the webapp while switching)
Linux:
ln -s target_name link_name
Vista/Windows 7:
mklink link_name target_name
In this way, you can still use c:\tomcat7\webapps\ , but specify symbolic links as follows:
mklink c:\tomcat7\webapps\coolName\ c:\myapps\xyz\webapp123\
(Note: For wars, you'd need to unzip the war first)
HTH
Your right in that you want to set the appBase paramete of the Host entry. Here is a previous question that discusses what it takes under windows : Apache Tomcat under Windows: Changing webapps default directory
As for how to change name of the app add a context.xml in the META-INF directory: Separating war application name from war file name