You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Glen Robson <gl...@llgc.org.uk> on 2009/11/04 11:34:58 UTC

Deploying Cocoon 2.2 to tomcat

Hi,

I'm trying to deploy cocoon to tomcat but I seem to be getting a  
conflict with the packaging type and maven. If I want the cocoon RCL  
plugin to run then the package type needs to be jar but if I want to  
deploy to tomcat the package type needs to be war (in the pom.xml). I  
can get the code working if I use jetty as it doesn't seem to require  
a war package. The results after running mvn package with the package  
type set to war:

[INFO] [cocoon:prepare {execution: prepare}]
[INFO] Don't execute the Cocoon RCL plugin becaues either its  
packaging type is not 'jar' or there is no rcl.properties file in the  
block's base directory.

The results of trying to deploy to tomcat if the project is set to jar:

[INFO] [jar:jar]
[INFO] Building jar: /Users/gmr/development/zoidberg_cocoon/target/ 
webapp-1.0.0.jar
[INFO] [tomcat:redeploy]
[INFO] Skipping non-war project

The tomcat, jetty and cocoon details from the pom.xml are:

33     <plugin>
  34         <groupId>org.apache.cocoon</groupId>
  35         <artifactId>cocoon-maven-plugin</artifactId>
  36         <version>1.0.0-M2</version>
  37         <executions>
  38           <execution>
  39             <id>prepare</id>
  40             <phase>compile</phase>
  41             <goals>
  42               <goal>prepare</goal>
  43             </goals>
  44           </execution>
  45         </executions>
  46       </plugin>
  47       <plugin>
  48         <groupId>org.mortbay.jetty</groupId>
  49         <artifactId>maven-jetty-plugin</artifactId>
  50         <version>6.1.7</version>
  51         <configuration>
  52           <connectors>
  53             <connector  
implementation="org.mortbay.jetty.nio.SelectChannelConnector">
  54               <port>8888</port>
  55               <maxIdleTime>30000</maxIdleTime>
  56             </connector>
  57           </connectors>
  58           <webAppSourceDirectory>${project.build.directory}/rcl/ 
webapp</webAppSourceDirectory>
  59           <contextPath>/</contextPath>
  60         </configuration>
  61       </plugin>
  62 <plugin>
  63          <groupId>org.codehaus.mojo</groupId>
  64          <artifactId>tomcat-maven-plugin</artifactId>
  65          <configuration>
  66          <url>http://localhost:8080/manager</url>
  67          <path>/cocoon-2.2</path>
  68          <username>******</username>
  69          <password>******</password>
  70       </configuration>
  71       </plugin>
  72 <plugin>

Any help would be greatly appreciated.

Thanks

Glen



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


Re: Deploying Cocoon 2.2 to tomcat

Posted by Dominic Mitchell <do...@happygiraffe.net>.
On Fri, Nov 6, 2009 at 3:12 PM, Glen Robson <gl...@llgc.org.uk> wrote:

> I moved the servlet to the block-servlet-service and it works great :D on
> jetty and tomcat.
>
>
Excellent news.

Given the non-documentation of the SSF, you may have a hard time figuring
> out what the correct values should be without looking at the source code. :(
>
>
> http://svn.apache.org/repos/asf/cocoon/trunk/subprojects/cocoon-servlet-service/
>
>
> Thanks for the link I've really struggled to find any information on the
> Servlet integration so Ill have a look in there to see whats going on.
>
> The most useful thing that I've found for exploring cocoon is the git
mirror.  If you run git clone git://git.apache.org/cocoon.git, you get a
full cocoon source tree with history.  Then you can do git
grep<http://www.kernel.org/pub/software/scm/git/docs/git-grep.html>to
quickly search through it all.  It's very handy.

Is writing code using Java Servlets and the SSF less the "cocoon way" than
> using flowscript or were you referring to the xweb use?
>

I was referring to using cocoon technologies rather than the servlet stuff.
 Where Cocoon provides something of course.  It can be difficult to get a
feel for this sort of thing, but as a rule of thumb, I reckon you should
start trying to solve any problem starting with FlowScript.


> I'm afraid I'm new to cocoon 2.2 but have used cocoon 2.1.1 for the last
> few years.
>

It took me a while to get used to 2.2  Although much of this was learning
maven rather than cocoon, it has to be said.

-Dom

Re: Deploying Cocoon 2.2 to tomcat

Posted by Glen Robson <gl...@llgc.org.uk>.
Hi Dom,

> I think that this is the wrong way of attaching a servlet to a  
> block.  If you have a look in META-INF/cocoon/spring/block-servlet- 
> service.xml, you need to define a bean for your servlet.  Then you  
> can get get rid of the xweb patching stuff, and cocoon's servlet  
> service framework dispatcher will take care of invoking your servlet  
> for you.
>
> I would guess that your bean should look like something like this:
>
> <bean name="uk.org.llgc.offair.maintance.servlet.service"  
> class="uk.org.llgc.offair.maintance.servlet.UploadXML">
>   <servlet:context mount-path="/offair_maintance/upload" context- 
> path="blockcontext:/offair_maintance/" />
>   <servlet:init-params>
>     <entry key="UploadXML" value="/usr/local/offair/maintenance"/>
>   </servlet:init-params>
> </bean>

I moved the servlet to the block-servlet-service and it works great :D  
on jetty and tomcat.

> Given the non-documentation of the SSF, you may have a hard time  
> figuring out what the correct values should be without looking at  
> the source code. :(
>
> http://svn.apache.org/repos/asf/cocoon/trunk/subprojects/cocoon-servlet-service/

Thanks for the link I've really struggled to find any information on  
the Servlet integration so Ill have a look in there to see whats going  
on.

>
> You may also wish to look at the upload sample in order to see how  
> to write your own upload code using FlowScript, avoiding the need  
> for a servlet entirely.
>
> http://svn.apache.org/repos/asf/cocoon/trunk/blocks/cocoon-core-sample/cocoon-core-main-sample/src/main/resources/COB-INF/sources/
>
> (look for upload://)
>
> Hopefully somebody with more cocoon experience than myself will jump  
> in here…
>
> … snip …
>
> Thanks for your help and I hope the above explanation makes sense.
>
> It does.  But I think you're making life hard for yourself by not  
> doing things in "the cocoon way".

Is writing code using Java Servlets and the SSF less the "cocoon way"  
than using flowscript or were you referring to the xweb use?

I'm afraid I'm new to cocoon 2.2 but have used cocoon 2.1.1 for the  
last few years.

Thanks for fixing the issue.

Glen


Deploying Cocoon 2.2 to tomcat

Posted by Dominic Mitchell <do...@happygiraffe.net>.
I just got bounced by the apache mail servers, so I'll try again…

-Dom

---------- Forwarded message ----------
From: Dominic Mitchell <do...@happygiraffe.net>
Date: Fri, Nov 6, 2009 at 12:40 PM
Subject: Re: Deploying Cocoon 2.2 to tomcat
To: users@cocoon.apache.org


On Thu, Nov 5, 2009 at 1:50 PM, Glen Robson <gl...@llgc.org.uk> wrote:

> I had a look at your example and my block and webapp is setup the same way
> but the only difference is I have a servlet in the block and I want to
> deploy it to tomcat.
>

Ah!  I think I'm beginning to see what's up now.


> No I use jetty for development and then deploy it to tomcat when I'm
> finished. Some more details on my application; I have one block called
> offair_maintance and a webapp block called zoidberg_cocoon.
>
> Block1 offair_maintance (packaging type jar)
>
> In here I've got some XML and XSL plus sitemap and a servlet with the
> following xweb:
>
> <xweb xpath="/web-app" insert-after="servlet[last()]">
>   <servlet>
>     <servlet-name>UploadXML</servlet-name>
>     <display-name>Upload XML</display-name>
>
>  <servlet-class>uk.org.llgc.offair.maintance.servlet.UploadXML</servlet-class>
>       <init-param>
>           <param-name>mrr_base_location</param-name>
>           <param-value>/usr/local/offair/maintance/</param-value>
>       </init-param>
>   </servlet>
>
>         <servlet-mapping>
>                 <servlet-name>UploadXML</servlet-name>
>             <url-pattern>/offair_maintance/upload/*</url-pattern>
>         </servlet-mapping>
> </xweb>
>
> so when developing on jetty I can go to
> http://localhost:8888/offair_maintance/upload/10/2009/MRR.xml which access
> the servlet and works great. The problem comes when I try to deploy to
> tomcat using the zoidberg_cocoon webapp.
>

I *think* that this is the wrong way of attaching a servlet to a block.  If
you have a look in META-INF/cocoon/spring/block-servlet-service.xml, you
need to define a bean for your servlet.  Then you can get get rid of the
xweb patching stuff, and cocoon's servlet service framework dispatcher will
take care of invoking your servlet for you.

I would guess that your bean should look like something like this:

<bean name="uk.org.llgc.offair.maintance.servlet.service"
class="uk.org.llgc.offair.maintance.servlet.UploadXML">
  <servlet:context mount-path="/offair_maintance/upload"
context-path="blockcontext:/offair_maintance/" />
  <servlet:init-params>
    <entry key="UploadXML" value="/usr/local/offair/maintenance"/>
  </servlet:init-params>
</bean>

Given the non-documentation of the SSF, you may have a hard time figuring
out what the correct values should be without looking at the source code. :(

http://svn.apache.org/repos/asf/cocoon/trunk/subprojects/cocoon-servlet-service/

You may also wish to look at the upload sample in order to see how to write
your own upload code using FlowScript, avoiding the need for a servlet
entirely.

http://svn.apache.org/repos/asf/cocoon/trunk/blocks/cocoon-core-sample/cocoon-core-main-sample/src/main/resources/COB-INF/sources/

(look for upload://)

Hopefully somebody with more cocoon experience than myself will jump in
here…

… snip …


> Thanks for your help and I hope the above explanation makes sense.
>

It does.  But I think you're making life hard for yourself by not doing
things in "the cocoon way".

-Dom

Re: Deploying Cocoon 2.2 to tomcat

Posted by Glen Robson <gl...@llgc.org.uk>.
Hi Dom,

On 5 Nov 2009, at 10:01, Dominic Mitchell wrote:
> You can probably arrange to deploy a built war file straight into a  
> running tomcat.  The docs suggest it should be as simple as "mvn  
> tomcat:deploy".
>
> I have heard of other people using the cargo plugin successfully (on  
> the maven mailing list).  In case you can't get the tomcat plugin to  
> do what you want, it may be an alternative.

Thanks I will give the cargo plugin a go.

>
> I've had the deployment working before but now I need to use xpatch  
> which requires the cocoon maven pugin to run to patch the web.xml.  
> So my problem is if I need the cocoon maven plugin to run the  
> packaging type needs to be jar but if I want to deploy to tomcat  
> then the packaging type needs to be war.
>
> You shouldn't need to use xpatch in the webapp module.  In the  
> webapp, you have full control of web.xml (under src/main/webapp/WEB- 
> INF/web.xml), so it's not necessary.
>
> You shouldn't have the cocoon maven plugin enabled in the webapp  
> project at all.  I went through the tutorial a little while back and  
> uploaded the result to github:  http://github.com/happygiraffe/cocoon-sample

I had a look at your example and my block and webapp is setup the same  
way but the only difference is I have a servlet in the block and I  
want to deploy it to tomcat.

>
> Are you trying to use tomcat for development?  I think that the  
> cocoon-maven-plugin is pretty much hard-wired to use jetty.   
> Deploying to tomcat is fine, but it does require building a full war  
> file, and then deploying that.  You won't get the same interactive  
> reloading that you do with jetty and the cocoon plugin.

No I use jetty for development and then deploy it to tomcat when I'm  
finished. Some more details on my application; I have one block called  
offair_maintance and a webapp block called zoidberg_cocoon.

Block1 offair_maintance (packaging type jar)

In here I've got some XML and XSL plus sitemap and a servlet with the  
following xweb:

<xweb xpath="/web-app" insert-after="servlet[last()]">
   <servlet>
     <servlet-name>UploadXML</servlet-name>
     <display-name>Upload XML</display-name>
     <servlet-class>uk.org.llgc.offair.maintance.servlet.UploadXML</ 
servlet-class>
       <init-param>
           <param-name>mrr_base_location</param-name>
           <param-value>/usr/local/offair/maintance/</param-value>
       </init-param>
   </servlet>

         <servlet-mapping>
                 <servlet-name>UploadXML</servlet-name>
             <url-pattern>/offair_maintance/upload/*</url-pattern>
         </servlet-mapping>
</xweb>

so when developing on jetty I can go to http://localhost:8888/offair_maintance/upload/10/2009/MRR.xml 
  which access the servlet and works great. The problem comes when I  
try to deploy to tomcat using the zoidberg_cocoon webapp.

Webapp block zoidberg_cocoon (packaging type war)

In here I add the dependency to offair_maintance in the pom.xml:

<dependency>
                         <groupId>uk.org.llgc</groupId>
                         <artifactId>offair_maintance</artifactId>
                         <version>1.0-SNAPSHOT</version>
                 </dependency>

then assuming I set the package type to war I can run:

mvn tomcat:deploy

and when I look on tomcat the offair_maintance block works OK apart  
from the servlet which gives a no pipeline error. When I look in the  
zoidberg_cocoon target directory I can see the UploadXML servlet isn't  
in the web.xml because the cocoon maven plugin hasn't run the  
UploadXML.xweb. If I change the packaging type to jar and run mvn  
jetty:run on the zoidberg_cocoon project then the servlet does work.

So is the only solution (assuming the cargo plugin doesn't fix this  
problem) to edit the web.xml in zoidberg_cocoon and all the servlets  
which are defined in the blocks I reference?

Thanks for your help and I hope the above explanation makes sense.

Thanks

Glen


Re: Deploying Cocoon 2.2 to tomcat

Posted by Dominic Mitchell <do...@happygiraffe.net>.
On Thu, Nov 5, 2009 at 9:19 AM, Glen Robson <gl...@llgc.org.uk> wrote:

> Hi Dom,
>
> On 4 Nov 2009, at 22:35, Dominic Mitchell wrote:
>
> You need two modules: one for the block and one for the webapp (you will
> probably also want a third, parent module to build them all in one shot).
>
> Don't try to edit the block's and set it's packaging to a war.  This simply
> won't work, as you've seen.  if you have a look at the tutorials, pay
> particular attention to the last one on deployment<http://cocoon.apache.org/2.2/1362_1_1.html>
> .
>
> Using the cocoon-maven-plugin and jetty:run is (as far as I can see)
> development time only.
>
> -Dom
>
>
> Thanks for your reply. I do have two block as you say one for the block and
> one for the webapp. The block packaging type is set to jar but its the
> webapp packaging type I'm confused with.
>

The webapp should definitely be packaged as "war".


> I've been following the tutorial you mentioned and it works well for jetty
> but I can't get it to work with tomcat. Am I using the correct tomcat maven
> plugin?
>
> 63          <groupId>org.codehaus.mojo</groupId>
> 64          <artifactId>tomcat-maven-plugin</artifactId>
>
>
I have no idea how the tomcat maven
plugin<http://mojo.codehaus.org/tomcat-maven-plugin/> works,
I'm afraid (though it does look like the right plugin).  I just manually
copy the war into an external tomcat when it's ready.  i.e after running
"mvn package" in the webapp module.

You can probably arrange to deploy a built war file straight into a running
tomcat.  The docs suggest it should be as simple as "mvn tomcat:deploy".

I have heard of other people using the cargo
plugin<http://cargo.codehaus.org/Maven2+plugin> successfully
(on the maven mailing list).  In case you can't get the tomcat plugin to do
what you want, it may be an alternative.


> I've had the deployment working before but now I need to use xpatch which
> requires the cocoon maven pugin to run to patch the web.xml. So my problem
> is if I need the cocoon maven plugin to run the packaging type needs to be
> jar but if I want to deploy to tomcat then the packaging type needs to be
> war.
>

You shouldn't need to use xpatch in the webapp module.  In the webapp, you
have full control of web.xml (under src/main/webapp/WEB-INF/web.xml), so
it's not necessary.

You shouldn't have the cocoon maven plugin enabled in the webapp project at
all.  I went through the tutorial a little while back and uploaded the
result to github:  http://github.com/happygiraffe/cocoon-sample

Are you trying to use tomcat for development?  I think that the
cocoon-maven-plugin is pretty much hard-wired to use jetty.  Deploying to
tomcat is fine, but it does require building a full war file, and then
deploying that.  You won't get the same interactive reloading that you do
with jetty and the cocoon plugin.

-Dom

Re: Deploying Cocoon 2.2 to tomcat

Posted by Glen Robson <gl...@llgc.org.uk>.
Hi Dom,

On 4 Nov 2009, at 22:35, Dominic Mitchell wrote:
> You need two modules: one for the block and one for the webapp (you  
> will probably also want a third, parent module to build them all in  
> one shot).
>
> Don't try to edit the block's and set it's packaging to a war.  This  
> simply won't work, as you've seen.  if you have a look at the  
> tutorials, pay particular attention to the last one on deployment.
>
> Using the cocoon-maven-plugin and jetty:run is (as far as I can see)  
> development time only.
>
> -Dom

Thanks for your reply. I do have two block as you say one for the  
block and one for the webapp. The block packaging type is set to jar  
but its the webapp packaging type I'm confused with.

I've been following the tutorial you mentioned and it works well for  
jetty but I can't get it to work with tomcat. Am I using the correct  
tomcat maven plugin?

63          <groupId>org.codehaus.mojo</groupId>
64          <artifactId>tomcat-maven-plugin</artifactId>

I've had the deployment working before but now I need to use xpatch  
which requires the cocoon maven pugin to run to patch the web.xml. So  
my problem is if I need the cocoon maven plugin to run the packaging  
type needs to be jar but if I want to deploy to tomcat then the  
packaging type needs to be war.

Thanks for your help

Glen


Re: Deploying Cocoon 2.2 to tomcat

Posted by Dominic Mitchell <do...@happygiraffe.net>.
On Wed, Nov 4, 2009 at 10:34 AM, Glen Robson <gl...@llgc.org.uk>wrote:

> I'm trying to deploy cocoon to tomcat but I seem to be getting a conflict
> with the packaging type and maven. If I want the cocoon RCL plugin to run
> then the package type needs to be jar but if I want to deploy to tomcat the
> package type needs to be war (in the pom.xml). I can get the code working if
> I use jetty as it doesn't seem to require a war package. The results after
> running mvn package with the package type set to war:
>

You need two modules: one for the block and one for the webapp (you will
probably also want a third, parent module to build them all in one shot).

Don't try to edit the block's and set it's packaging to a war.  This simply
won't work, as you've seen.  if you have a look at the tutorials, pay
particular attention to the last one on
deployment<http://cocoon.apache.org/2.2/1362_1_1.html>
.

Using the cocoon-maven-plugin and jetty:run is (as far as I can see)
development time only.

-Dom