I'm doing some deploy / start / stop tests locally on my computer, and it would be very comfortable to have my webapps deployed (so they can be managed throught the Tomcat manager webapp) but not started right away when Tomcat start.
Is this feasible at all?
Within the documentation I only found how to deploy or not deploy a webapp at all (through the "Host" configuration in server.xml).
This is a portion of my server.xml:
<Host name="host1.localpc" appBase="C:\tools\tomcat\webapps\host1" unpackWARs="true" autoDeploy="true" deployIgnore="^(?!ROOT$).*?$" deployOnStartup="true">
<Context docBase="C:\tools\tomcat\runnable\apache-tomcat-7.0.69\webapps\manager" path="/manager" privileged="true" />
</Host>
<Host name="host2.localpc" appBase="C:\tools\tomcat\webapps\host2" unpackWARs="true" autoDeploy="true" deployIgnore="^(?!ROOT$).*?$" deployOnStartup="true">
<Context docBase="C:\tools\tomcat\runnable\apache-tomcat-7.0.69\webapps\manager" path="/manager" privileged="true" />
</Host>
<Host name="host3.localpc" appBase="C:\tools\tomcat\webapps\host3" unpackWARs="true" autoDeploy="true" deployIgnore="^(?!ROOT$).*?$" deployOnStartup="true">
<Context docBase="C:\tools\tomcat\runnable\apache-tomcat-7.0.69\webapps\manager" path="/manager" privileged="true" />
</Host>
Hostnames are handled throught the Windows HOSTS file.
I'm running Tomcat 7.0.69
Hum... Certainly, as far as I know, any war is automatically started by Tomcat just after being deployed. Still, I'd suggest you to take a look at the Tomcat Client Deployer, a module from which you can get an Ant script to deploy-and-stop your application. To accomplish this, you should:
Download the TCD.
Parametrize the build.xml.
Invoke ant deploy stop to deploy and stop.
Hello I'm trying to deploy .war application from the public_html folder at user homes.
I've added directive to server.xml :
<Listener className="org.apache.catalina.startup.UserConfig"
directoryName="public_html"
userClass="org.apache.catalina.startup.PasswdUserDatabase"/>`
And I try :
http://localhost:8080/~usertest/app
And it return : 404 error
Then I try : http://localhost:8080/~usertest/app.war
It download app.war but it doesn't serve the app.
User home contains folder :
public_html/app.war
So, what is the problem?
I'm using tomcat 7
After many tries, and ask on tomcat mail-list, It's not possible to deploy (and execute) WAR files inside public_html user's homes.
Tomcat haven't this feature, but there is one alternative:
Create one virtual host per user (hostname, or port), where each user deploy war applications, like (server.xml) :
...
<Connector port="8082" ....
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="app_user_a" unpackWARs="true" autoDeploy="true">
...
<Connector port="8083" ....
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="app_user_b" unpackWARs="true" autoDeploy="true">
...
I'm using Jenkins for war deployment to my remote server which uses Tomcat 7.
I need my application to be directly installed at dedicated port like this:
http://localhost:8083
instead of usual:
http://localhost:8080/myCoolApp
To achieve this I deploy my war archive as ROOT directly to 'webapp' Tomcat's directory.
Everything works fine, archive is sent and deployed but I get an error from Jenkins:
Just to remind - archive is deployed successfully!
But as a perfectionist I just can't stand a result like this.
Here is my configuration for Jenkins deployment:
Here is Tomcat configuration for my application as a separate service:
<Service name="Jangel">
<Connector port="8083" protocol="HTTP/1.1"
connectionTimeout="20000" redirectPort="8443" />
<Engine name="Jangel" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase" />
<Host name="localhost" appBase="Jangel" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
</Host>
</Engine>
So the question is - how should I configure correctly Tomcat&Jenkins?
Or how may I avoid/silence this Jenkins error?
Try this by replacing the context path in your jenkins deployment by / (slash) instead of writing ROOT.
I deploy a application to tomcat with context xml. I want the tomcat work at debug mode, I means if I change something inside a function, like change
String a="123";
to
String a="456";
tomcat should get the change without reload the application.
The web01.xml under %CATALINA_HOME%/conf/Catalina/localhost
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="d:/document/workspace3.6/web01/WebContent" path="/web01" reloadable="false" debug="1" ></Context>
but now tomcat didn't worked as I expected, if I replace the old class file with new version, I must restart tomcat to get the change.
Why tomcat didn't reload the class,How should I do to let it work as debug mode?
I am not use Eclipse now. and I don't want to set reloadable="true", this will reload the entire application if class changed.
I used tomcat5.5.23
You're actually confusing the notions of "debugging" and hot deploy. You can configure Tomcat for debug mode, and then remotely debug your application running inside tomcat such that when you add a break point in your code, the debugger will jump to that breakpoint and halt execution.
What you actually need there is having the possibility to hotdeploy an application. With tomcat, if you modify the .java files and then copy them to the working directory of tomcat, you'll get exactly what you want, namely the ability to change something in a class and have the running tomcat-deployed application take it into account without redeploying the whole application. You can automatize this by configuring your tomcat application context (either in the tomcat server.xml file or in a project specific context.xml file) for your application to have as working directory the directory where your project code gets compiled.
here's an actual example:
Let's say you have a maven project in the directory c:\myProject. You'd have source files in the c:\myProject\src, and then when compiling it you'd get the war file and an exploded directory of the war file content in the c:\myProject\target\myProject.war and respectively c:\myProject\target\myProject. Now, if you configure your tomcat such that for the myProject tomcat context, youd have the working directory configured as c:\myProject\target\myProject, then each time you modify a .java file, the .class corresponding file will be updated in the target (and now also working) dir, and tomcat will take it into account.
I've actually used such a setup to develop with tomcat, but it's not the best. First off tomcat will hotdeploy only certain modifications, such as when you modify something in the body of an existing method. Other modifications will not be taken into account, such as adding a new method - for this you have to do a full redeploy to have it taken into account.
A far better solution is to use maven with the maven jetty plugin. This thing really works as you want: any modification you do to a class of jsp file will me immediately taken into account, and visible in the running app inside jetty.
Ok, here's an actual example:
I have the cnas-war maven project. Once I build it with Maven, I get the following directory:
c:/_andrei/work/cnas/cnas-war/target\cnas-war-0.0.1-SNAPSHOT
In here I have all the stuff that normally would get packaged in the .war file, like .class files, .jsp files, .jar files etc. Effectively it's the .war file exploded.
I also have a Tomcat 5.5 specifically tailored for the deployment of this war, cleverly placed in the tomcat_cnas folder. In the Tomcat config file (conf\server.xml) I have the following:
<?xml version="1.0" encoding="utf-8"?>
<!-- Example Server Configuration File -->
<!-- Note that component elements are nested corresponding to their
parent-child relationships with each other -->
<!-- A "Server" is a singleton element that represents the entire JVM,
which may contain one or more "Service" instances. The Server
listens for a shutdown command on the indicated port.
Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" or "Loggers" at this level.
-->
<Server port="8125" shutdown="SHUTDOWN">
<!-- Comment these entries out to disable JMX MBeans support used for the
administration web application
<Listener className="org.apache.catalina.core.AprLifecycleListener" />
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/> -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<!-- Global JNDI resources -->
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer"
value="30" />
<Resource auth="Container"
configurationDirectory="c:/cnas-content"
factory="com.genia.toolbox.web.jndi_config.StringContainerFactory"
name="string/activitymanagerConfigurationContainer"
type="com.genia.toolbox.web.jndi_config.StringContainer" />
<Resource name="string/activitymanagerConfigurationContainer"
auth="Container"
type="com.genia.toolbox.web.jndi_config.StringContainer"
factory="com.genia.toolbox.web.jndi_config.StringContainerFactory"
configurationDirectory="c:/cnas-content" />
</GlobalNamingResources>
<!-- Define the Tomcat Stand-Alone Service -->
<Service name="Catalina">
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector acceptCount="100" connectionTimeout="20000"
disableUploadTimeout="true" enableLookups="false"
maxHttpHeaderSize="8192" maxSpareThreads="75" maxThreads="150"
minSpareThreads="25" port="8081" redirectPort="8443" />
<!-- Define the top level container in our container hierarchy -->
<Engine defaultHost="localhost" name="Catalina">
<!-- for activitymanager -->
<Host name="localhost" appBase="webapps" unpackWARs="true"
autoDeploy="true" xmlValidation="false"
xmlNamespaceAware="false">
<Context path="/cnas"
docBase="c:/_andrei/work/cnas/cnas-war/target/cnas-war-0.0.1-SNAPSHOT/"
workDir="c:/_andrei/work/cnas/cnas-war/target/work-cnas/">
<ResourceLink name="string/configurationContainer"
global="string/activitymanagerConfigurationContainer"
type="com.genia.toolbox.web.jndi_config.StringContainer" />
<Resource name="bean/cnasConfig" auth="Container"
type="com.genia.toolbox.projects.cnas.war.config.CnasConfig"
factory="org.apache.naming.factory.BeanFactory"
classpath="false" fileSystem="true"
applicationFileLocation="c:/cnas-content/application.properties" />
<Resource name="bean/cnasApplicationData"
auth="Container"
type="com.genia.toolbox.projects.cnas.war.config.CnasConfig"
factory="org.apache.naming.factory.BeanFactory"
classpath="false" fileSystem="true"
applicationFileLocation="c:/cnas-content/cnas_application_data.xml" />
</Context>
<!--Context docBase="C:/travail/workspace/cnas/cnas-ws-proxy/target/webapp" path="/proxy">
<Resource name="bean/params"
auth="Container"
type="fr.genia.cnas.config.Parameters"
factory="org.apache.naming.factory.BeanFactory"
log4jFile=""
serviceUrl=""
debugMode="true" >
</Resource>
</Context-->
</Host>
</Engine>
</Service>
</Server>
As you can see, in the "context" tag I have a docBase property pointing to the snapshot directory (the one where the war is exploded after maven builds it). Now, with this setup, and having this project imported into Eclipse, if I do a maven build, and then start this Tomcat, the war will be deployed and running. At this point, if I modify the content of a method in a .java file inside Eclipse (and save), then that code will be automatically taken into account by Tomcat and the application will behave differently, without any extra re-deployment. Hope this helps
How to configure Tomcat 5.5 for debug mode?
To do what you are trying to do, You would need some thing like java rebel or some thing similar I know there are some open source alternatives to do the same.
My JSF application is deployed under tomcat and server.xml is configured as follows for my application
<Host name="myapp.com" appBase="/home/myapp/public_html">
<Alias>www.myapp.com</Alias>
<Context path="" reloadable="true" docBase="/home/myapp/public_html" debug="1"/>
<Context path="/manager" debug="0" privileged="true" docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>
</Host>
With these settings I can access all the pages under 'web' folder. I have 'app' folder under 'web' and I have couple of jsp pages under 'app', when I try to access some pages available under 'app' with the following URL: www.myapp.com/app/test_page.jsf, I get 'requested resource cannot be found'
What are the changes I need to do in Tomcat`s Server.xml to get this working.
Do I need to add context path for the 'app' subcontext like this mentioned below in Server.xml:
<Context path="/myapp/app" reloadable="true" docBase="/home/myapp/public_html/app" debug="1"/>
Assuming that /web folder is placed in /public_html folder, you need to include the /web folder in either appBase and docBase, or in URL.