cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robby Pelssers" <robby.pelss...@ciber.com>
Subject RE: The "Using Blocks" tutorial
Date Sun, 24 Oct 2010 09:21:53 GMT
Ok... this time some sample pom's i made up based on my actual project.

Assuming you have a workspace like:

{workspace}
  - mywebapp_parent_pom
  - block-1
  - block-2

parent pom of your application:
---------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<project 
  xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <packaging>pom</packaging>
  
  <groupId>com.mycompany</groupId>
  <artifactId>mywebapp_parent_pom</artifactId>
  <version>1.0-SNAPSHOT</version>
  
  <name>MyWebapp parent pom</name>
  
  <modules>
    <module>../block-1</module>
    <module>../block-2</module>                     
  </modules>
  
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.apache.cocoon</groupId>
        <artifactId>cocoon-core</artifactId>
        <version>2.2.0</version>
      </dependency>
      <dependency>
        <groupId>org.apache.cocoon</groupId>
        <artifactId>cocoon-servlet-service-components</artifactId>
        <version>1.0.0</version>
      </dependency>
      <dependency>
        <groupId>org.apache.cocoon</groupId>
        <artifactId>cocoon-template-impl</artifactId>
        <version>1.1.0</version>
      </dependency>
      <dependency>
        <groupId>org.apache.cocoon</groupId>
        <artifactId>cocoon-flowscript-impl</artifactId>
        <version>1.0.0</version>
      </dependency>    
      <dependency>
        <groupId>org.apache.cocoon</groupId>
        <artifactId>cocoon-forms-impl</artifactId>
        <version>1.1.0</version>
      </dependency>
      <dependency>
        <groupId>org.apache.cocoon</groupId>
        <artifactId>cocoon-html-impl</artifactId>
        <version>1.0.0</version>
      </dependency>
      <dependency>
        <groupId>org.apache.cocoon</groupId>
        <artifactId>cocoon-batik-impl</artifactId>
        <version>1.0.0</version>
      </dependency>
      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.4</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>net.sf.saxon</groupId>
        <artifactId>saxon</artifactId>
        <version>8.7</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.4</version>
        <scope>test</scope>
      </dependency>
  </dependencyManagement>
  
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  
  <profiles>
    <profile>
      <id>dev</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>	  
      <build>
        <finalName>MyWebapp</finalName>
      </build>
    </profile>
  </profiles>
  
</project>


pom of block-1:
--------------------
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <parent>
    <groupId>com.nxp.spider2</groupId>
    <artifactId>mywebapp_parent_pom</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../mywebapp_parent_pom/pom.xml</relativePath>
  </parent>
  
  <modelVersion>4.0.0</modelVersion>
  <packaging>jar</packaging>

  <name>block-1</name>
  <groupId>com.mycompany</groupId>
  <artifactId>block-1</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>org.apache.cocoon</groupId>
      <artifactId>cocoon-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.cocoon</groupId>
      <artifactId>cocoon-servlet-service-components</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.cocoon</groupId>
      <artifactId>cocoon-template-impl</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.cocoon</groupId>
      <artifactId>cocoon-flowscript-impl</artifactId>
    </dependency>     
    <dependency>
      <groupId>org.apache.cocoon</groupId>
      <artifactId>cocoon-forms-impl</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.cocoon</groupId>
      <artifactId>cocoon-batik-impl</artifactId>
    </dependency>        
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
    </dependency>  
    <dependency>
      <groupId>net.sf.saxon</groupId>
      <artifactId>saxon</artifactId>
      <scope>runtime</scope>
    </dependency>
                     
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </dependency>    
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.cocoon</groupId>
        <artifactId>cocoon-maven-plugin</artifactId>
        <version>1.0.0-M2</version>
        <executions>
          <execution>
            <id>prepare</id>
            <phase>compile</phase>
            <goals>
              <goal>prepare</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.7</version>
        <configuration>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>8888</port>
              <maxIdleTime>30000</maxIdleTime>
            </connector>
          </connectors>
          <webAppSourceDirectory>${project.build.directory}/rcl/webapp</webAppSourceDirectory>
          <contextPath>/</contextPath>
          <systemProperties>
            <systemProperty>
              <name>org.apache.cocoon.mode</name>
              <value>dev</value>
            </systemProperty>
          </systemProperties>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.1</version>
        <configuration>
          <archive>
            <manifestEntries>
              <Cocoon-Block-Name>${pom.artifactId}</Cocoon-Block-Name>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.5</version>
      </plugin>
    </plugins>
  </build>

</project>


pom of block-2:
----------------
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <parent>
    <groupId>com.nxp.spider2</groupId>
    <artifactId>mywebapp_parent_pom</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../mywebapp_parent_pom/pom.xml</relativePath>
  </parent>

  <modelVersion>4.0.0</modelVersion>
  <packaging>jar</packaging>

  <name>block-2</name>
  <groupId>com.mycompany</groupId>
  <artifactId>block-2</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>com.mycompany</groupId>
      <artifactId>block-2</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>  
    <dependency>
      <groupId>org.apache.cocoon</groupId>
      <artifactId>cocoon-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.cocoon</groupId>
      <artifactId>cocoon-servlet-service-components</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.cocoon</groupId>
      <artifactId>cocoon-template-impl</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.cocoon</groupId>
      <artifactId>cocoon-flowscript-impl</artifactId>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
    </dependency>
    <dependency>
      <groupId>net.sf.saxon</groupId>
      <artifactId>saxon</artifactId>
      <scope>runtime</scope>
    </dependency>    
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </dependency>     
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.cocoon</groupId>
        <artifactId>cocoon-maven-plugin</artifactId>
        <version>1.0.0-M2</version>
        <executions>
          <execution>
            <id>prepare</id>
            <phase>compile</phase>
            <goals>
              <goal>prepare</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.7</version>
        <configuration>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>8888</port>
              <maxIdleTime>30000</maxIdleTime>
            </connector>
          </connectors>
          <webAppSourceDirectory>${project.build.directory}/rcl/webapp</webAppSourceDirectory>
          <contextPath>/</contextPath>
          <systemProperties>
            <systemProperty>
              <name>org.apache.cocoon.mode</name>
              <value>dev</value>
            </systemProperty>
          </systemProperties>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.1</version>
        <configuration>
          <archive>
            <manifestEntries>
              <Cocoon-Block-Name>${pom.artifactId}</Cocoon-Block-Name>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.5</version>
      </plugin>
    </plugins>
  </build>
</project>


As you can see i declared 2 modules in the parent pom.  Actually you would also need a webapp
project as well in order to build the complete webapp. But that's for later. Let us first
get you started with those 2 blocks.

I also declared in block-2 a dependency on block-1. But if we were to install both blocks
and run mvn jetty:run from inside the folder block-2, block-2 would start properly on http://localhost:8888/block-2
but http://localhost:8888/block-1 would not work yet. You also need to change our servlet-service
spring context.


E.g.:

  <bean name="com.nxp.spider2.producttransformer.service" class="org.apache.cocoon.sitemap.SitemapServlet">
    <servlet:context mount-path="/block-2" context-path="blockcontext:/block-2/">
      <servlet:connections>
        <entry key="block-1" value-ref="com.mycompany.block-1.service"/>       
      </servlet:connections>    
    </servlet:context>
  </bean>

So after you made those changes you should be able to run the second block and you should
be able to call services from block-1 as well.

Hope this clarifies enough.

Kind regards,
Robby Pelssers

Mime
View raw message