How to configure apache tomcat to point to my project? - apache

I have apache tomcat running into a specific server and I've deployed a project named where2go. So I have a file named:
where2go.war and I deployed this one.
Right now when I try to access this link:
where2go.ca is going to no where and you get a blank page.
If I want to access the project I need to go to:
where2go.ca/where2go
How do I configure my server to show where2go project when I access where2go.ca?

If I understand right your question, you want to put your project on the root of the server and call it like the following: where2go.ca/ instead of where2go.ca/where2go/
If so, in order to achieve that, you need to modify your server.xml (you can find it in the tomcat configuration folder.
Open the server.xml file using your favorite text editor, and add the following directive the file, before the </Engine> directive
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="where2go" reloadable="true" override="true"></Context>
</Host>
The above will change your server root path to your project folder.
This change is good when you don't have other project deployed on the same server.
Another solution (to my opinion less preferable) is to manually deploy your project into the ROOT folder inside your /webapps folder.
Hope it will help,
Liron

After looking a while I found the solution on this link:
How can I remove the application name from a Grails application’s URL?
I used the 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)]

Related

Tomcat server.xml redirection: new class files not loaded

I have have a domain name (for example myapp.com) that I am using it to redirect to a web application (for exmple "myapp"), which is deployed on my tomcat server (for example in "myserver.es/myapp"). I added this fragment to the server.xml file of the tomcat to configure the redirection:
<Host name="myapp.com" appBase="webapps/myapp"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/" docBase="."/>
<Alias>www.myapp.com</Alias>
</Host>
Apparently it is working good, if I write "mydomain.com" in the browser the app is shown correctly.
The problem: when I generate a new WAR file of that app and I upload it to the Tomcat server (after stopping and undeploying the previous version), the changes related with Java code are not shown. I have to restart my tomcat server to access to the last version of the app from "myapp.com".
In contrast, if I access to "mydomain.com/myapp", I can see the last version of the app, showing the changes made in the last WAR.
So, I think that the problem is related with the redirection. It is anything wrong with the previous XML code?
The other "Host" configured in the server.xml is this one:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
You might be having issues with Parallel Deployement
You could set undeployOldVersions="true" inside your host to see if that works.
Finally, I've discovered the solution! I needed to set privileged="true" inside the Context tag.

How to preserve Apache Tomcat7 configuration files when reinstalling application

I am using Apache Tomcat7 for one of my projects and in order to store some container specific configuration, I am using an XML file under the /etc/tomcat7/Catalina/localhost/ directory (in linux). For example /etc/tomcat7/Catalina/localhost/my-app.xml if the app in question is called my-app.
When I reinstall (update) the application, the afore mentioned file, seems to be deleted during the installation process. Is there any way to preserve this file?
Yes! Have done this mistake quite some time.
There are several conditions (like changing the war file, deleting the webapp or replacing it with new content) under which tomcat will undeploy the context including removing the context file.
You should stop your server before making any changes like changing your war file. If you try to edit or move the deployed war file the corresponding configuration in conf/Catalina/localhost/ will get deleted.
If you do not wish this behavior you can edit the server.xml file located in conf/ directory.
Change
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
and make autoDeploy="false"
For more details you can refer to Apache Tomcat Configuration Reference

Running jsp files from /srv/http using Apache HTTP server and Tomcat

I'd like run jsp files directly from /srv/http without deploying them the Tomcat-way. For example, I want to be able to create symbolic link to my webapp directory (e.g. /home/user/myapp/) in /srv/http and access some app's page through http://localhost/myapp/page.jsp.
Is this possible and how would I set this up?
NOTE: This is not for production. We have to use JSP at university and I want to be able to quickly test my pages.
Open the server.xml of your Tomcat. Assuming if your are using Tomcat 6.x+ then it would be at /tomcatDir/conf/server.xml.
Make an entry with your path
<Context path="/myapp" docBase="yourPathGoesHere" debug="0" reloadable="true" />
Restart Tomcat if already running.
What I did at the moment was creating a symlink in /var/lib/tomcatX/webapps to my project path. This is not the answer I was looking for though, but it is a way to deploy an app without much work.
(X in the above path means your Tomcat version)
If you set <Host name="localhost" appBase="/srv/http"> then all of the directories in it will be deployed as web applications.
If you want /srv/http to be the ROOT application/directory add a file: tomcat/conf/Catalina/localhost/ROOT.xml
with the Context docBase="/srv/http", rather than adding a Context definition to server.xml - this has been strongly discouraged for years.

Apache tomcat deployment

I have a war file which is a simple dynamic web application where I will call a JSP file which calls a Java file and does some stuff. There is no servlet programming involved.
I deployed the war file in the webapps folder of the tomcat folder.
I restarted the server, the application is extracted and when i call the jsp file like below it is working like a charm.
localhost:8080/Login/login.jsp
But i want to create a directory structure in the webapps folder and place the war file in it and access it as follows
the directory structure is
<tom cat folder>webapps/myapp/mylogin/<my war file>
what i did was copied the extracted war file from the webapps folder and pasted it in the above directory structure
When i accessed it like below it is throwing error
localhost:8080/myapp/mylogin/Login/login.jsp
Please let me know how to host my war file with directory structure in webapps folder.
Hope i was clear in my question.
That should work. What is the error in the log files (access log file, stdout/stderr) and on the screen ?
I need to make a mapping in the server.xml file.
<Host name="showcase.com" appBase="webapps/myapp/mylogin/"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>

Best way to have tomcat app reside at /

At work we have many Spring apps running on one tomcat server. Some of the apps have their own domains with a virtualhost in apache that rewrites requests from /url to /context_root/url.
This is all fine and good except for when I use some of springs tag libs that handle urls. An example is the <form:form> tag which creates an action of /context_root/form and takes the user away from /. Now, the app still works when that happens but management doesn't want to see the context root.
What is the best way to tackle this?
In case anyone stumbles into this, I did end up finding the answer.
With Tomcat you can have multiple hosts. So I setup a host with my app as the default webapp. Here's an example:
Add another Host to server.xml
<Host name="lilhug.mydomain.com" appBase="lilhug"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false"/>
Create some files and directories
mkdir $CATALINA_HOME/lilhug
mkdir $CATALINA_HOME/conf/Catalina/lilhug.mydomain.com
If you want the Tomcat manager for this host
cd $CATALINA_HOME/conf/Catalina
cp localhost/manager.xml lilhug.mydomain.com
Then restart tomcat and you're good. Deploy the lilhug app to / using the /manager running at your new host or copy the war to $CATALINA_HOME/lilhug/ROOT.war