Deploy webapp manually with Tomcat (ie autoDeploy=false, noDeployOnStartup=false) - java

I'm trying to deploy several web applications to tomcat 6.x, and I've turned off autoDeploy and onDeployStartup because I want to manually register these apps and map them to URLs not based on the names of their war files.
I've put the following context file in $catalina.home/conf/Catalina/localhost:
<Context path="" docBase="web-1.0-SNAPSHOT.war" debug="1">
</Context>
And I put the war file under $catalina.home/webapps, but when I startup tomcat nothing gets deployed. I don't even see any error messages about the context files I created. Or any print outs saying anything is wrong.
What's the problem? I've read the documents which outlines autodeploy a lot, but is very sketchy on details of how to do this outside of autodeploy.

So the details about how autoDeploy works, and alternative deployments is only really discussed here.:
http://wiki.apache.org/tomcat/HowTo#How_do_I_make_my_web_application_be_the_Tomcat_default_application.3F
I don't know why tomcat makes this so complicated. If you turn off autoDeploy your only option is to modify the server.xml and add your contexts there. You can't externalize the definitions of your contexts which seems convoluted way to deploy things. If I'm going to take the time to drop a XML config file I should be able to control the URL it's mounted to and the docBase. Just make it straight forward because Jetty does.

Try the following steps
Shutdown the tomcat
Copy web-1.0-SNAPSHOT.war to webapps folder.
Deploy the webapp.
Now there is a folder named web-1.0-SNAPSHOT inside webapps.
go to conf/server.xml
Add the following entries
<Context path="/abc" docBase="web-1.0-SNAPSHOT" debug="1"></Context>
The docbase doesn't have the .war extention. When web-1.0-SNAPSHOT.war is deployed there will be a directory web-1.0-SNAPSHOT inside webapps. The docbase should point to this directory.
Please make sure that Context tag is within the
<Host> </Host> tag
<Host>
<Context path="/abc" docBase="web-1.0-SNAPSHOT" debug="1"></Context>
</Host>
After editing server.xml you have to restart tomcat server to reflect the changes.
Now you can find your webapp at
localhost:8080/abc
Hope this helps

Setting deployonstartup to false tells tomcat not to deploy apps on startup. I think its enough to turn autodeploy off. so maybe try the following in the Host in server.xml: autoDeploy="false" deployOnStartup="true".

Example code
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false" deployOnStartup="false">
<Context path="/howto-prepareexam" docBase="howto-prepareexam" debug="1"></Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
Then restart tomcat

Related

Deploying War. Tomcat not taking context.xml from META-INF in consideration

I do have a Spring Boot Application which uses custom context.xml for the tomcat.
The context.xml contains property, defining the spring active profile
<Context>
<Environment name="spring.profiles.active" value="profileName" type="java.lang.String" override="false" />
</Context>
File location is the /src/main/webapps/META-INF
I was expecting that after the file is deployed to the tomcat, context xml will be automatically picked by tomcat and thrown to the conf/catalina/localhost/
As it turned out, the war was deployed, but the conf/catalina/localhost stayed empty.
After reading the docs i've found out that the server.xml has to be updated with the copyXML parameter as Host container.
The documentation says:
copyXML
Set to true if you want a context XML descriptor embedded inside the application (located at /META-INF/context.xml) to be copied to xmlBase when the application is deployed. On subsequent starts, the copied context XML descriptor will be used in preference to any context XML descriptor embedded inside the application even if the descriptor embedded inside the application is more recent. The flag's value defaults to false. Note if deployXML is false, this attribute will have no effect.
My Host looks like
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true" copyXML="true">
</Host>
After restarting the server and redeploying the app, the /conf/Catalina/localhost still stayed empty.
Do you have any suggestions, what actions have to be taken in order to use custom context.xml?
I've figured it out.
My build script did not copy the file correctly, the file name was not "context.xml" but "appName.xml" and tomcat didn't pick it up.

Tomcat issues with Host, Contexts and webapp double instances

/...too long and unclear explanation.../
In other way, I search the correct way to reach the site with just (one or more) domain name (then www.my_domain.it and not www.my_domain.it/appname), and all of these must point to the same instance of the webapp (so that from any domain name you access, the same Runtime data will always be displayed).
So, yes I have deployed the WAR file in tomcat/webapps folder, now, the correct to edit the conf/server.xml to get the result mentioned above, corresponds to one of the following?
1.
<Host name="my_domain.eu" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Alias>www.my_domain.eu</Alias>
<Alias>www.my_domain.it</Alias>
<Alias>www.my_domain_2.it</Alias>
<Context path="" docBase="appname" debug="0" privileged="true" />
...
</Host>
2.
<Host name="my_domain.eu" appBase="webapps/appname" unpackWARs="true" autoDeploy="true">
<Alias>www.my_domain.eu</Alias>
<Alias>www.my_domain.it</Alias>
<Alias>www.my_domain_2.it</Alias>
<Context path="" docBase="appname" debug="0" privileged="true" />
...
</Host>
3.
<Host name="my_domain.eu" appBase="webapps/appname" unpackWARs="true" autoDeploy="true">
<Alias>www.my_domain.eu</Alias>
<Alias>www.my_domain.it</Alias>
<Alias>www.my_domain_2.it</Alias>
<Context path="/appname" docBase="appname" debug="0" privileged="true" />
...
</Host>
4.
<Host name="my_domain.eu" appBase="webapps/appname" unpackWARs="true" autoDeploy="true">
<Alias>www.my_domain.eu</Alias>
<Alias>www.my_domain.it</Alias>
<Alias>www.my_domain_2.it</Alias>
<!-- without context definition -->
...
</Host>
Otherwise, what is the correct solution?
Thanks to all!
I'm assuming that you have one of the instances of your app in the webapps directory, from where it's automatically deployed under its name. With the Context element, you can deploy applications from anywhere in the filesystem.
However, it's best practice to not edit server.xml with this information, but rather create individual context.xml files in conf/hostname, or just deploy to the host's webapps directory. Anything that you're configuring in server.xml requires a server restart if you want to change anything. Configuration outside of server.xml can be picked up at runtime, without restart.
Edit: Probably the takeaway of my previous answer wasn't clear:
When you use Context elements to configure: I'm proposing not to use the webapps directory for deploying your webapps. Just point to the directory where you actually deployed your webapp. This will make sure that no context is deploying your app from webapps/appname as /appname, even though your context definition points to /.
An alternative is to deploy your application with the name ROOT in webapps - this is a shortcut to actually deploy this webapp as / (careful: ALL CAPS for the directory- or file-name (ROOT.war) even on Windows if I remember correctly). But IMHO it would be clearer if you decide for either Context definition to determine the path (but deploy outside of appbase (webapps), or deployment in appbase (e.g. webapps) deployment.
Mocking around with appbase to point to some directory within webapps will make sure that you irritate anyone who is expecting that applications in webapps directory will deploy to Tomcat. That's an easy way to sink a lot of time into debugging phantom problems - don't do that.

How can I specify "Context path" on Tomcat 8 inside META-INF/context.xml in java war file?

How can I deploy mywebapp-1.0.0.war to $TOMCAT_HOME/webapps directory with context path /mywebapp using context.xml inside the war file on Tomcat 8?
I'm getting back to work with Tomcat after long time since version 5. I'm used to create META-INF/context.xml inside my war file:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/mywebapp">
...
</Context>
Maven creates a war file with this name: mywebapp-1.0.0.war
But when I deploy the war file to $TOMCAT_HOME/webapps directory the context path will be http://localhost:8080/mywebapp-1.0.0 instead of http://localhost:8080/mywebapp/.
Also I see that $TOMCAT_HOME/conf/Catalina/localhost is empty, instead of having the xml file copied from the war file deployed.
I also added to $TOMCAT_HOME/conf/server.xml the deployXML="true"
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
deployXML="true">
It is not possible to put a war inside the webapp directory and set the path attribute in META-INF/context.xml file at the same time. Tomcat 8 documentation, clearly says about this attribute:
This attribute must only be used when statically defining a Context in server.xml. In all other circumstances, the path will be inferred from the filenames used for either the .xml context file or the docBase.
Can't you just rename your war file to mywebapp (via Maven or else) so that Tomcat will deploy it under /mywebapp ?
Thanks for your research j2gl!
I've found out that good way how to achieve both .war file with full name with version and deployed short path is to use Tomcat manager API. For example through Tomcat7-maven-plugin.

URL rewriting in tomcat 7 when hitting domain name

I need help in redirecting URL for an application deployed in tomcat7.
When we use "www.portal.com/portal", am able to view the site.
I want to view the page by just entering the URL as "www.portal.com". So, i need help in what need to be modified in tomcat7 configuration to get this done.
You can name your application ROOT or change the path to your application in tomcat's server.xml file.
This is an example of a mapping in the server.xml file:
<Context docBase="portal" path="/portal" reloadable="true"
source="org.eclipse.jst.jee.server:portal" />
To load the portal application without using /portal you need to change it to:
<Context docBase="portal" path="" reloadable="true"
source="org.eclipse.jst.jee.server:portal" />

issue with tomcat context setting in server.xml

I am using tomcat 7.
When I set context different from war file name, everything works fine.
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context docBase="../webapps/abc.war" path="/def" reloadable="true" />
</Host>
But at tomcat startup I see two exploded folder abc and def.
Please help if anybody knows about this issue resolution.
Thanks.
From the Tomcat doc (see "path" attribute):
Even when statically defining a Context in server.xml, [the path] attribute
must not be set unless either the docBase is not located under the
Host's appBase or both deployOnStartup and autoDeploy are false. If
this rule is not followed, double deployment is likely to result.
This is a bit obscur, but my understanding is that you need to use an xml context file to achieve what you are trying to do. How to define a context config file is documented in the above link.
A simpler fix would be to just rename your war file to def.war.

Categories

Resources