Apache tomcat deployment - apache

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>

Related

How to set custom JSP project url to default url on using tomcat8 local server?

I setup Tomcat8 and upload jsp project in webapps directory.
Now I can visit my site with the url like "http://sitename/project name/web".
But I hope my project to show when visit "http://sitename".
I tried to find solution but nothing is helpful.
Please help me.
Thank you.
Try making the directory named ROOT in webapps directory and put into your jsp file and rename to index.jsp.
If you create ROOT directory or ROOT.war in webapps directory, then the application can be accessed without /[context-name], like "http://sitename/your.jsp".
In addition, Tomcat regards index.jsp as the welcome file by the following default settings in conf/web.xml:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
So you can access to ROOT/index.jsp by requesting to "http://sitename".

How to configure apache tomcat to point to my project?

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)]

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

Unable to find httpd.conf

I'm running tomcat and I want to change the default webroot so that it points to another location. Is there a way to find out what's running tomcat or where the default webroot is set as I can't find httpd.conf which is where I believe it's usually set?
Cheers,
Alexei Blue.
**UPDATE:**
It's been a long time since I looked at this question that I forgot about it. In the end it turned out that we were using Apache HTTPD to accept requests from port 80. From there we had the webroot and ProxyPass rules set in the /etc/httpd/conf/virtual-hosts/default.conf file (these can also be set in /etc/httpd/conf/httpd.conf). From there we had several tomcat instances running, all hosted on different ports which are setup in apache-tomcat-x/conf/server.xml.
When I wrote this question I was trying to setup a new tomcat instance to run an application in development and was told I would need to change the webroot to access my application, which was incorrect. Instead what I needed was to include a ProxyPass rule so that when my application name was recognised in the URL, HTTPD would send the request to the correct tomcat instance to be processed.
E.g.
www.domain.com/myApplication
In /etc/httpd/conf/virtual-hosts/default.conf
ProxyPass /myApplication/ ajp://127.0.0.1:<ajp_port>/myApplication/
ProxyPassReverse /myApplication/ ajp://127.0.0.1:<ajp_port>/myApplication/
Where the ajp_port is setup in apache-tomcat-x/conf/server.xml. I needed to ensure that non of the ports conflicted with other tomcat instances so remember to check all ports i.e. Shutdown, HTTP, HTTP with SSL, AJP etc.
Tomcat doesn't use httpd.conf, that is an apache file. The location of the individual webapps are kept in their individual web.xml files, but the location of all the configs are in ../tomcat6/conf/server.xml and web.xml
Is it where the files come from you want to move, or where it compiles and executes them from?
As #Woody says, Tomcat does not use httpd.conf files: that's an Apache httpd thing (httpd is a web server, Tomcat is a Java application server).
You didn't mention what OS you are using or what package management software you are using (e.g. yum, apt, etc.) so I'll give you generic information as if you had downloaded and installed Tomcat directly from apache.org (which I usually recommend people do for a number of reasons).
Tomcat keeps its server-wide configuration in the conf/server.xml file in the Tomcat base installation directory (often called $CATALINA_BASE for convenience): here, you configure things like what types of connectors (e.g. HTTP, HTTPS, AJP, etc.) to use and which ports they should listen to, clustering configuration, session persistence, global JNDI and realm resources. There are also conf/web.xml and conf/context.xml files that define defaults for all webapps deployed on that instance of Tomcat, but it's best to leave those files alone unless you have a really good reason to modify them.
When you want to deploy a webapp (under the default configuration), all you need to do is drop a .WAR file into the $CATALINA_BASE/webapps/ directory and the webapp will be deployed into a "context path" (aka URL prefix) that matches the name of the file minus the ".WAR" suffix. So, if you have a WAR file called mygreatwebapp.war, then it will be deployed such that your clients can reach it at http://yourhost/mygreatwebapp/. There is a special name you can give a WAR file so that it has an empty context path: if you name your WAR file ROOT.war (case matters), then your webapp can be reached at http://yourhost/. (If you would rather use exploded-WAR directories instead of WAR files, everything above still applies except the directories simply don't have the .war extension).
Given your original question, it sounds like all you want to do is drop a ROOT.war file into $CATALINA_BASE/webapps (or replace the one that is already there): this will deploy whatever webapp you want into the URL space that you might call the "default webroot".
Update
If you want to change the directory where all the webapps live for a host, you can modify $CATALINA_BASE/conf/server.xml and change the <Host>'s appBase attribute to point to, say, /cfusion/main/www/. That will deploy all the WAR files and directories in /cfusion/main/www/ as separate webapps.
If you just want to serve a single webapp from an arbitrary location, you may create a deployment file under $CATALINA_BASE/conf/[EngineName]/[HostName]/[appname].xml. This is a standard file like META-INF/context.xml and contains a <Context> element except that you will have to specify a docBase which points to your webapp (e.g. /cfusion/main/www/mywebapp).

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.