You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Kevin Jackson <fo...@gmail.com> on 2006/11/14 10:17:09 UTC

tomcat deployer

Hi all,

I'm trying to work on a webapp with tomcat and mvn.  I want to be able
to edit a jsp, type mvn tomcat:redeploy and have just the changed jsp
be reloaded, without having to compile/package/deploy

I'm fairly sure that this is possible using a combination of mvn +
tomcat-plugin, but I'm failing the correct incantation test

so far I can do a mvn tomcat:deploy, but this
compiles/filters/packages and takes forever - not good for rapid
development of ui stuff

mvn tomcat:redeploy seems to just redeploy the application that's
already deployed in the CATALINA_HOME/webapps directory, what I need
is some way to configure the plugin to deploy my development directory
as an exploded web application

Thanks in advance for any/all help

Kev

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: tomcat deployer

Posted by Adam Hardy <ad...@cyberspaceroad.com>.
Kevin Jackson wrote:
>> This gets discussed fairly regularly and there's multiple ways to handle
>> it.
>> If you're not aware, there's a great search engine for this list at
>> http://www.nabble.com/Maven---Users-f178.html
> 
> I actually find Nabble to be close to useless as it doesn't seem to
> get spidered by google properly, certainly MARC is my preferred place
> to find stuff out - shame maven list isn't there :(

http://marc.theaimsgroup.com/?l=turbine-maven-user&r=1&w=2



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: tomcat deployer

Posted by Gr...@Countrywide.Com.
"Kevin Jackson" <fo...@gmail.com> wrote on 11/15/2006 07:07:38 PM:

> > The way I've setup things I can see the changed jsp without calling
> > any maven target. There's more details of my solution here
> > http://www.nabble.com/Eclipse-war-builder-tf2371898s177.html#a6646490
> > Another fellow wrote a custom eclipse plugin to help him.
> 
> Could you go into more details?  I've followed what I could from your
> post ^^ but I still cannot get Tomcat to deploy just the context.xml
> file and use the target directory as an exploded webapp.  My guess is
> that I've setup tomcat incorrectly, but a working example of what to
> do would be great (I also tried the eclipse war builder thing and
> again it didn't work for me).

Here's a writeup I did for the team. I'll do my best to answer any
questions that it doesn't clarify.

Preliminaries

You'll need to edit a file in your tomcat installation to allow access to 
the manager webapp. These instructions are based upon tomcat 5.5.17, but 
should be similar for any 5.x installation. If not, please update this 
wiki once it is figured out.

In {tomcat-install-dir}/conf/tomcat-users.xml add the following:

<user username="admin" password="" roles="tomcat,manager,admin"/>

inside the <tomcat-users> element. Go to http://localhost:8080/manager and 
undeploy your application if it is already there. Also remove any war 
files and directories for your app under the webapps directory. (Re)start 
tomcat and you're ready.

Maven Targets

Now you can do:

mvn compile war:inplace tomcat:inplace

as your initial setup. You should now be able to see your deployed app in 
tomcat. Editing JSPs in eclipse will be seen immediately upon a refresh of 
the web page. If you edit any Java classes that the JSPs depend upon, you 
can do:

mvn compile war:inplace

to get tomcat to see the updates.

If at any time your context.xml file changes, you can tell tomcat about it 
by doing:

mvn tomcat:inplace

I haven't tried this, but it might be useful to modify the eclipse 
settings to direct compiled classes into the WEB-INF/classes directory. 
This should remove the need to ever do mvn compile war:inplace since a 
compile inside eclipse would put the modified classes there. Then only 
when the context.xml file changes would maven need to be involved.

Behind the Scenes

So, how does this work? The context.xml file lives in src/main/resources 
and the pom.xml is configured to filter this. That means we can do 
variable substitution. The context.xml file uses a variable that is based 
upon ${basedir} which maven knows as the directory the pom.xml files lives 
within. So, we can use this to tell tomcat to look inside the project 
directory for the exploded webapp.

war:inplace is a built-in maven goal that knows to create the exploded 
webapp inside src/main/webapp. However, this goal does not have any 
prerequisites, so whenever you use it, you must also do a compile (or test 
if you want to run unit tests too). war:inplace actually copies the 
external jars into WEB-INF/lib and the compiled classes into 
WEB-INF/classes, so subversion needs to be configured to ignore these (by 
adding a svn:ignore property to the WEB-INF directory ? I've already done 
this for SpecialLoans). Additionally, the pom.xml has been modified to 
tell the clean target to additionally delete those directories.

There's a feature request in maven that will help simplify some of this, 
like allowing the war:inplace to require compile and test as 
prerequisites, but due to various reasons, it can't be done in maven 
2.0.4. We can update this wiki page when this changes.
POM Involvement

Here are the relevant sections of the pom.xml that must be set in order 
for the whole scheme above to work. At some point this, or something 
similar, should become part of our basepom and archetypes, but until then, 
the information is preserved.

<properties>
        <docbase.on.server>${basedir}/src/main/webapp</docbase.on.server>
        <webapp.reloadable>true</webapp.reloadable>
</properties>
<build>
...
    <resources>
        <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
        </resource>
    </resources>

  <plugins>
  ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        <configuration>
                        <update>true</update>
                        <mode>context</mode>
 <contextFile>target/classes/context.xml</contextFile>
      </configuration>
      </plugin>
      <plugin> <!-- clean up from war:inplace  -->
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
                <filesets>
                        <fileset>
 <directory>${basedir}/src/main/webapp/WEB-INF/lib</directory>
                        </fileset>
                        <fileset>
 <directory>${basedir}/src/main/webapp/WEB-INF/classes</directory>
                        </fileset>
                    </filesets>
        </configuration>
      </plugin>

The context.xml lives in src/main/resources and looks like this:
<Context docBase="${docbase.on.server}" reloadable="${webapp.reloadable}">
...

Greg Vaughn
greg_vaughn@countrywide.com

======================================================================
Confidentiality Notice: The information contained in and transmitted with this communication is strictly confidential, is intended only for the use of the intended recipient, and is the property of Countrywide Financial Corporation or its affiliates and subsidiaries.  If you are not the intended recipient, you are hereby notified that any use of the information contained in or transmitted with the communication or dissemination, distribution, or copying of this communication is strictly prohibited by law.  If you have received this communication in error, please immediately return this communication to the sender and delete the original message and any copy of it in your possession.
======================================================================

Re: tomcat deployer

Posted by Kevin Jackson <fo...@gmail.com>.
Hi,

> This gets discussed fairly regularly and there's multiple ways to handle
> it.
> If you're not aware, there's a great search engine for this list at
> http://www.nabble.com/Maven---Users-f178.html

I actually find Nabble to be close to useless as it doesn't seem to
get spidered by google properly, certainly MARC is my preferred place
to find stuff out - shame maven list isn't there :(

>
> The way I've setup things I can see the changed jsp without calling
> any maven target. There's more details of my solution here
> http://www.nabble.com/Eclipse-war-builder-tf2371898s177.html#a6646490
> Another fellow wrote a custom eclipse plugin to help him.

Could you go into more details?  I've followed what I could from your
post ^^ but I still cannot get Tomcat to deploy just the context.xml
file and use the target directory as an exploded webapp.  My guess is
that I've setup tomcat incorrectly, but a working example of what to
do would be great (I also tried the eclipse war builder thing and
again it didn't work for me).

Thanks
Kev

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: tomcat deployer

Posted by Gr...@Countrywide.Com.
"Kevin Jackson" <fo...@gmail.com> wrote on 11/14/2006 03:17:09 AM:

> Hi all,
> 
> I'm trying to work on a webapp with tomcat and mvn.  I want to be able
> to edit a jsp, type mvn tomcat:redeploy and have just the changed jsp
> be reloaded, without having to compile/package/deploy
> 
> I'm fairly sure that this is possible using a combination of mvn +
> tomcat-plugin, but I'm failing the correct incantation test
> 
> so far I can do a mvn tomcat:deploy, but this
> compiles/filters/packages and takes forever - not good for rapid
> development of ui stuff
> 
> mvn tomcat:redeploy seems to just redeploy the application that's
> already deployed in the CATALINA_HOME/webapps directory, what I need
> is some way to configure the plugin to deploy my development directory
> as an exploded web application

This gets discussed fairly regularly and there's multiple ways to handle 
it.
If you're not aware, there's a great search engine for this list at
http://www.nabble.com/Maven---Users-f178.html

The way I've setup things I can see the changed jsp without calling
any maven target. There's more details of my solution here
http://www.nabble.com/Eclipse-war-builder-tf2371898s177.html#a6646490
Another fellow wrote a custom eclipse plugin to help him.

If you actually want to call tomcat:redeploy before seeing the changed
jsp, you may want to look at the tomcat:inplace goal or maybe 
war:exploded.

Greg Vaughn
greg_vaughn@countrywide.com

======================================================================
Confidentiality Notice: The information contained in and transmitted with this communication is strictly confidential, is intended only for the use of the intended recipient, and is the property of Countrywide Financial Corporation or its affiliates and subsidiaries.  If you are not the intended recipient, you are hereby notified that any use of the information contained in or transmitted with the communication or dissemination, distribution, or copying of this communication is strictly prohibited by law.  If you have received this communication in error, please immediately return this communication to the sender and delete the original message and any copy of it in your possession.
======================================================================