Deploy .war file from another directory to Tomcat 6 - deployment

If it is possible, how do I deploy a war file from another directory (say D:\foo.war) to Tomcat 6, without copying it into the webapps directory of Tomcat?
If not, is there any configuration to change the default webapp folder to some other folder?

You can do both.
how do I deploy a war file from another directory (say D:\foo.war) to Tomcat 6, without copying it into the webapps directory of Tomcat?
Add a Context xml file to conf/Catalina/localhost. The name of the file should be the name that you want for the context. For example, if my URL is http://your.domain.com/my-context then the name of the file would be my-context.xml. Inside that XML file add something like this.
<?xml version="1.0"?>
<Context docBase="d:\foo.war">
</Context>
The docBase attribute should point to your WAR file or an exploded WAR directory. See more on this here.
If not, is there any configuration to change the default webapp folder to some other folder?
In conf/server.xml locate your Host tag and set the appBase attribute. This defaults to webapps, but you can change it to any location that you like.
Ex:
<Host appBase="d:\my-web-apps" ...>
For best results, point to local storage and not network storage (i.e. NFS or Samba).

Simply specify a context entry in your server.xml (under <Host> </Host>
<Context docBase="xyz/abc.war" path="/myapp" reloadable="true"/>

Related

Can we change Jboss default deploy folder path?

Let's assume I've war file in one location in file system and I have Jboss server installed at different location in file system.Now my question is there any way Jboss can access my war file directly.
In short I don't want to move my war file in deploy folder instead I want location of war file to be treated as deploy folder.
Is it possible??If yes then how?
Add path of custom deployment directory in standalone-*xml like :
<paths>
<path name="custom.dir" path="/PATH_TO/jboss/applications"/>
</paths>
and then in deployment-scanner subsystem mention it like :
<subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">
<deployment-scanner path="customDeployDir" relative-to="custom.dir" > scan-interval="5000"/>
</subsystem>

Jetty deploy war file (Automatic Deployment is not working)

this is my first time deploying a war File to a Jetty Server via SCP+SSH and I'm not able to get it to work.
I made a proper .war file with Eclipse (but I also tested the same things I'm going to mention with a example .war file) and copied the file to the folder /jetty/webapps/ROOT. Now when I restart Jetty and try to get on the server (I tried Serveradress/WarFilename/ aswell) I get to a Directory Path and I'm able to download the war file but nothing else.
I also tried to copy the war file to the webapps folder itself instead of webapps/ROOT. What am I doing wrong?
The directory ${jetty.base}/webapps/ROOT/ is for exploded webapps, or static resource deployments.
If you want to serve your war file, say myapp.war on the root context "/", then copy it to the file ${jetty.base}/webapps/ROOT.war
Note: if you are copying the file into the jetty-distribution/webapps/ you are doing it wrong, go read up on how ${jetty.base} and ${jetty.home} work.

Eclipse WebContent directory deployment in tomcat

In Eclipse, the folder structure when I create a Dynamic Web Project is
[srikanth#hana Sample]$ ls -R
.:
build src WebContent
./build:
classes
./build/classes:
./src:
./WebContent:
index.html META-INF scripts WEB-INF
./WebContent/META-INF:
MANIFEST.MF
./WebContent/scripts:
jquery-1.7.1.js
./WebContent/WEB-INF:
lib web.xml
./WebContent/WEB-INF/lib:
As you can see, there is this WebContent directory, When I copy the directory structure from Eclipse workspace and put in webapps directory of Tomcat, it didn't work. But, if I moved all the directories and files under WebContent directory a level above, it worked fine.
This is the folder structure in Tomcat's webapps directory under application:
[srikanth#hana Sample]$ ls -R
.:
build index.html META-INF scripts src WEB-INF
./build:
classes
./build/classes:
./META-INF:
MANIFEST.MF
./scripts:
jquery-1.7.1.js
./src:
./WEB-INF:
lib web.xml
./WEB-INF/lib:
So, now I can just go to http://localhost:8080/Sample and can go to index.html properly
What am I doing wrong? Why didn't it work just copying the application
from Eclipse to tomcat webapps directory directly? Why do I have to
change the directory structure?
I had the same problem, ./WebContent/index.html not appearing in the Eclipse-exported .war. This occurred on my new Eclipse system after I recreated a working project from my old system with Kepler Eclipse to a new system with Luna Eclipse.
I fixed this by going to Project / Properties / Deployment Assembly. I discovered that the old working system had this rule, while my new non-working systems was missing this rule ...
Source = /WebContent
Deploy Path = /
I corrected this on the new system by Pressing "Add..." and adding the missing rule.
Eclipse allows deploying the webapp directly to a server, without needing to copy anything by yourself. It also allows generating a deployable war file when you're ready to deploy to a test or production server.
Open the "Servers" view, right-click, and choose to create a new server. Once created, right-click on the server and choose to add your web-app into it. And then Eclipse will deploy your web-app to the server.
You're not supposed to manually copy anything from Eclipse. And if you need or want to do this, then you should probably use some ant script which generates the proper deployment structure. This structure is described in the servlet specification. It should have, under the root directory of the webapp, a WEB-INF directory containing:
classes: a directory containing your classes
lib: a directory containing all the jar files your app depends on
web.xml the webapp's deployment descriptor
All the other directories and files that are not under WEB-INF can be served by the web container.
When I copy the directory structure from Eclipse workspace and put in
webapps directory of Tomcat, it didn't work. But, if I moved all the
directories and files under WebContent directory a level above, it
worked fine
Not sure what you mean if I moved all the directories and files under WebContent directory a level above, it worked fine here and what you mean by saying a level above.
What you should be doing is not copy anything manually but right-click on the project and select Export as WAR option.
This will create a file named Project.war that contains the proper file structure i.e. WEB-INF etc that you are supposed to put under tomcat's webapps dir

Location of jsp class file inside war file

When I am creating a war file for struts2.xx project called 'test'. I want to know where my *.jsp are converted into *.class, can you tell me the exact location of jsp's class file inside my war file? Environment Should running in Tomcat7.xx
Jsp's generated class files wont go inside the war file. You can find them in the Servlet Containers directory (for tomcat it will be something like ${CATALINA_BASE}\work\Catalina\localhost\${WebAppName}\org\apache\jsp)

Deploy war file with modifiable properties files

I am building a web service and am packaging it into a war file for deployment. Right now all of my config files (.properties and .xml) are being packaged into my .war file. This isn't going to work as some of these files will need to be modified for each individual installation. I know that some servlet containers will leave the .war files intact which would mean the config files would never be easily modified. My question is this: what is the best practice for deploying a .war file with these external config files? I'm thinking that the config files will need to be shipped separate from the .war file and placed into a directory that is in the classpath. Is there a default directory setup like this in Tomcat that these files can just be dropped into and my web service will be able to find without much trouble?
Maybe I shouldn't be using a war file for this setup? Maybe I should just be providing a zip file (with the same contents as the war file) and the deployment will simply be to extract the zip into the webapps directory?
I do not know any default directory in Tomcat to store configuration, my
attempts to solve the same issue have been :
1 - Move configuration to the DB and provide scripts or webpages to modify values.
2 - Have a script to deploy the war. The script would merge configuration from a user directory into web.xml or other deployed config files.
3 - Have webapps look first in a user directory for configuration and
if not found then look for configuration files deployed by the war.
Least favorite is 3 - it require all webapps to check two places for configuration and
you end up with two different xml files on the server with different values and it is not always clear which one is used.
Next favorite is 2 - the webapps can be written without knowledge of multiple config files, but you run into issue when someone does a deploy from Tomcat manager instead of using your script.
Favorite is 1. This just works in most cases. Problem is when you don't have a DB or
want to configure how you connect to the DB.
If having the file visible from all webapps is not an issue, you could put it $CATALINA_HOME/lib.
One solution is to modify property file after deployment of war file is to use ServletContext.getRealpath() method to get the real path means path of file in the server where it is deployed and then modify that file it will modify file in container only not the original file. So you need to backup it if it is important modification for you. So by this you do not need to redeploy war file as it is already modifying file from deployed container.
This solution can edit a file that is in webpages folder also from the java class.
If you want more description or how to do it then let me know i have did it.