Deploying Web Apps as war Files - java

I'm having some trouble uploading and getting my web app on the net with my chosen host. I built a war file in Net Beans and asked my host to deploy it for me. This worked fine but to access it I had to point my browser to:
www.myDomain.co.uk/explodedWar
What of course I wanted was to be able to access it just by pointing my browser at:
www.myDomain.co.uk
The war file contains the whole app, index.html, images, classes etc.
Is this possible or am I missing something ? ?

You can call the war ROOT.war but the best way is to change the context path in the servlet container. To do this in Tomcat you would add the following to your server.xml:
<context path="" docBase="explodedWar" debug="0"/>

If you name your war ROOT.war (in Tomcat) it should do what you want.

This is a question you need to ask your host about since they are deploying it for you.

Related

How to have spring MVC app direct to generic .com url

So for example, if my project name is WebApp and my domain is www.google.com, when running locally I have to type in www.google.com/WebApp. That's not super easy for clients, so I was wondering if there is a way to direct to a home page when typing in www.google.com? Any tips appreciated.
Where are you deploying? To get to www.google.com you have to deploy to the root context or point the root to where you deployed.
Deploying my application at the root in Tomcat
You have a couple of options:
Remove the out-of-the-box ROOT/ directory from tomcat and rename your
war file to ROOT.war before deploying it.
Deploy your war as (from
your example) war_name.war and configure the context root in
conf/server.xml to use your war file :
The first
one is easier, but a little more kludgy. The second one is probably
the more elegant way to do it.

Deploying .war application in Tomcat to root

My .war application runs on TomCat
I am able to deploy my .war application to a specific directory e.g. www.abc.com/specific
I would do this by renaming my application specific.war and then going to Tomcat Web Application Manager and then going to "WAR file to deploy", select my WAR file and deploy it.
However I would like to deploy it so that if the user types www.abc.com he/she will go straight to the application, without specifying the directory.
How is this possible? Thanks [I have tried calling the application root.war]
Two ways:
name the war file ROOT.war
specify the context path attribute in META-INF/context.xml - see here
I solved this by using forwarding/masking (through the domain name provider)
I forwarded www.abc.com to www.abc.com/specific
and I masked so that "specific" is not shown
I am not sure if this answers your question. But I believe u can automatically navigate to the page u want using the
<welcome-file></welcome-file>
in the web.xml file of ur web app.

Preventing access to war file without using .htaccess / apache conf

Currently when I deploy a war file to Tomcat it can be downloaded from the URL via something like foo.com/myapp.war.
Most places recommend that you put an entry in a .htaccess file to prevent public access to any war files, or failing that an equivalent entry in your Apache config.
Unfortunately, my host does not provide access to the Apache config (although I can access Tomcat confs) and .htaccess files do not work for all Tomcat/Java related hosting environments. Pretty disappointing. They have been rather unhelpful in this respect.
Without resorting to something like "finding another host" (other than this issue they are fine - I'd rather stay here until my app grows too big), is there anything else I can do to prevent public users accessing my war files, yet still allow Tomcat to deploy the apps when it scans them?
For example, is it possible to specify one directory for Tomcat to scan for war files yet have it deploy the war into the public directories?
Thanks.
It is probably better to ask at https://serverfault.com/. It all boils down to how Tomcat is setup.
The vanilla setup will have a folder called webapps under CATALINE_HOME. You put your WAR archives there (they get auto-extracted and deployed). These folders will not be accessible from HTTP (you cannot download WAR archives from some URL like /webapps/my-test.war). These apps in webapps folder are deployed to some context roots. For example an application my-test.war will by default get deployed as yourhost.com/my-test/.
If you can download your WAR archives from foo.com/myapp.war maybe you can check out what does the CATALINA_HOME/webapp/ROOT app is doing. By default this is deployed under the foo.com. Ask from the host the Tomcat configuration files to figure what kind of custom configurations are they using.
You can place your .war files in any location Tomcat has access to. But you will have to tell Tomcat about it, so it picks them up. You can do this by placing a configuration XML file in
<CATALINA_HOME>/conf/Catalina/localhost/myWebapp.xml
There are samples on what to put into that file myWebapp.xml, e. g. here, step "4)". And of course, the official documentation.

How to deploy a Java Web Application (.war) on tomcat?

I have a .war file of a Java Web Application. Now I want to upload it to my ftp server so that I can execute it.
What steps I should perform to run it?
The context path of the webapp is /mywebapp
Edit
Actually, my ftp server name is ftp://bilgin.ath.cx/ and I have uploaded my TestWebApp.war file to this dir: ftp://bilgin.ath.cx/web
Then what should be the URL to access the index.html page of the webapplication
#2 Edit
Tomcat is listening on 8082
Apache access Tomcat with jk connector.
As others pointed out, the most straightforward way to deploy a WAR is to copy it to the webapps of the Tomcat install. Another option would be to use the manager application if it is installed (this is not always the case), if it's properly configured (i.e. if you have the credentials of a user assigned to the appropriate group) and if it you can access it over an insecure network like Internet (but this is very unlikely and you didn't mention any VPN access). So this leaves you with the webappdirectory.
Now, if Tomcat is installed and running on bilgin.ath.cx (as this is the machine where you uploaded the files), I noticed that Apache is listening to port 80 on that machien so I would bet that Tomcat is not directly exposed and that requests have to go through Apache. In that case, I think that deploying a new webapp and making it visible to the Internet will involve the edit of Apache configuration files (mod_jk?, mod_proxy?). You should either give us more details or discuss this with your hosting provider.
Update: As expected, the bilgin.ath.cx is using Apache Tomcat + Apache HTTPD + mod_jk. The configuration usually involves two files: the worker.properties file to configure the workers and the httpd.conf for Apache. Now, without seeing the current configuration, it's not easy to give a definitive answer but, basically, you may have to add a JkMount directive in Apache httpd.conf for your new webapp1. Refer to the mod_jk documentation, it has a simple configuration example. Note that modifying httpd.conf will require access to (obviously) and proper rights and that you'll have to restart Apache after the modifications.
1 I don't think you'll need to define a new worker if you are deploying to an already used Tomcat instance, especially if this sounds like Chinese for you :)
copy the .war file in the webapps folder
upload the file using the manager application - http://host:port/manager. You will have to setup some users beforehand.
(not recommended, but working) - manually extract the .war file as a .zip archive and place the extracted files in webapps/webappname
Sometimes administrators configure tomcat so that war files are deployed outside the tomcat folder. Even in that case:
After you have it deployed (check the /logs dir for any problems), it should be accessible via: http://host:port/yourwebappname/. So in your case, one of those:
http://bilgin.ath.cx/TestWebApp/
http://bilgin.ath.cx:8080/TestWebApp/
If you don't manage by doing the above and googling - turn to your support. There might be an alternative port, or there might be something wrong with the application (and therefore in the logs)
The tomcat manual says:
Copy the web application archive file into directory $CATALINA_HOME/webapps/. When Tomcat is started, it will automatically expand the web application archive file into its unpacked form, and execute the application that way.
Note that you can deploy remotely using HTTP.
http://localhost:8080/manager/deploy
Upload the web application archive
(WAR) file that is specified as the
request data in this HTTP PUT request,
install it into the appBase directory
of our corresponding virtual host, and
start it using the war file name
without the .war extension as the
path. The application can later be
undeployed (and the corresponding
application directory removed) by use
of the /undeploy. To deploy the ROOT
web application (the application with
a context path of "/"), name the war
ROOT.war.
and if you're using Ant you can do this using Tomcat Ant tasks (perhaps following a successful build).
To determine which path you then hit on your browser, you need to know the port Tomcat is running on, the context and your servlet path. See here for more details.
Log in :URL = "localhost:8080/"
Enter username and pass word
Click Manager App
Scroll Down and find "WAR file to deploy"
Chose file and click deploy
Done
Go to Webapp folder of you Apache tomcat you will see a folder name matching with your war file name.
Type link in your url address bar:: localhost:8080/HelloWorld/HelloWorld.html and press enter
Done

Making a java web application as the root of a domain name in Tomcat 6

I'm currently developing a Java web application myapp and when deployed in Tomcat 6 server, I access myapp with this URL: http://localhost:8080/myapp
Instead I want to access my application using this URL: http://myapp:8080 since myapp will be the only application deployed in my Tomcat 6.
How do I do it?
This can be done in Tomcat in basically two ways:
Set path attribute of <Context> element in Webapp/META-INF/context.xml (or Tomcat/conf/server.xml, depending where you'd like to define it) to an empty String. E.g.
<Context path="">
Rename it to ROOT.war and Tomcat will automagically deploy it as ROOT.
Outside Tomcat there are more ways to do this, such as (virtual) proxy, URL rewriting with .htaccess, etcetera.
Im assuming you meen you want your url to be http://localhost:8080 not http://myapp:8080.
If you dont need the default apps that come with tomcat then just go to your webapps directory (where myapp is probably located) and look for another folder called ROOT (in my Tomcat 6). rename ROOT to something else and rename myapp to ROOT. This is a quick and messy way that works because the default host's appBase is webapps and the default app is ROOT.
If you had access to the tomcat/conf/ directory then you could edit the server.xml file but Im not very knowledgeable about server.xml so I wont try and walk you through it.

Categories