views:

31

answers:

1

Hi experts,

I have a developed application and I am just trying to make the build process easy. The POM file for parent looks like this:

<parent>
    <groupId>com.shc.obu.ca</groupId>
    <artifactId>shcobuca-pom</artifactId>
    <version>1.1.0</version>   </parent>

  <groupId>com.shc.obu.ca.osol</groupId> <artifactId>apps-pom</artifactId>   <version>${currVersion}</version>   <packaging>pom</packaging>   <name>Outlet Apps</name>

  <scm>
    <connection>scm:svn:https://ushofsvpsvn2.intra.searshc.com/svn/outlet/outlet/trunk/apps&lt;/connection&gt;
    <developerConnection>scm:svn:https://ushofsvpsvn2.intra.searshc.com/svn/outlet/outlet/trunk/apps&lt;/developerConnection&gt; </scm>
    <profiles>
    <profile> <id>www</id>
      <activation> <activeByDefault>true</activeByDefault> </activation>
      <modules>
        <module>www</module>
        <module>modules</module> 
      </modules>
    </profile>
    <profile> 
      <id>mts</id>
      <activation> <activeByDefault>true</activeByDefault> </activation>
      <modules>
        <module>mts</module> 
        <module>modules</module> 
      </modules>
    </profile>
    <profile> <id>search</id>
      <activation> <activeByDefault>true</activeByDefault> </activation>
      <modules>
        <module>modules</module> 
        <module>search</module> 
      </modules>
    </profile>   </profiles>

  <repositories>
    <repository>
      <id>obu.ca.repo.release</id>
      <snapshots><enabled>false</enabled></snapshots>
      <url>http://maven.cal.intra.sears.com/release&lt;/url&gt;
    </repository>
    <repository>
      <id>obu.ca.repo.snapshot</id>
      <releases><enabled>false</enabled></releases>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>interval:5</updatePolicy>
      </snapshots>
      <url>http://maven.cal.intra.sears.com/snapshot&lt;/url&gt;
    </repository>   </repositories>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <env>trunk</env>
    <currVersion>1.2.0</currVersion>   </properties>   </project>

This file shows that it has three profiles which are basically independent child project. I am adding the cargo plugin to this file as below:

<build>
  <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <container>
              <containerId>tomcat6x</containerId>
              <home>
                  C:\tools\apache-tomcat-6.0.26
              </home>
          </container>
          <configuration>
              <properties>
                  <cargo.servlet.port>
                      8082
                  </cargo.servlet.port>
                  <cargo.jvmargs>
                      "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n"
                  </cargo.jvmargs>
              </properties>
          </configuration>     
        </configuration>  
      </plugin>
  </plugins>
  </build>

But when I run 'mvn cargo:start', tomcat instance runs fine but none of the child apps get deployed. Is there a way that I can make my first child application (www) (which generates a war file called www-webapp-1.2.0.war) auto deployed?

Update: Thanks Pascal. I tried modifying the build tag as below:

<build>
  <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <container>
              <containerId>tomcat6x</containerId>
              <home>
                  C:\tools\apache-tomcat-6.0.26
              </home>
          </container>
          <configuration>
              <properties>
                  <cargo.servlet.port>
                      8082
                  </cargo.servlet.port>
                  <cargo.jvmargs>
                      "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n"
                  </cargo.jvmargs>
              </properties>              
              <deployables> 
                <deployable> 
                  <groupId>com.shc.obu.ca.osol</groupId> 
                  <artifactId>www-webapp-1.2.0</artifactId> 
                  <type>war</type> 
                  <properties> 
                    <context>acontext</context> 
                  </properties> 
                </deployable> 
              </deployables>               
          </configuration>    
        </configuration>  
      </plugin>
  </plugins>
  </build>

But still it's not working. It's giving build error as below:

Artifact [com.shc.obu.ca.osol:www-webapp-1.2.0:war] is not a dependency of the project. I tried 'www-webapp' and 'www' as artifact id as well but the error remained the same.

And when I add the same to dependency tags, it gives some kind of cyclic reference error as below: 'The projects in the reactor contain a cyclic reference'

A: 

You need to list your www module as a module to deploy inside a <deployable> element. From the Maven2 Plugin Reference Guide:

If no deployable is specified and the project's packaging is war, ear or ejb and there is no deployer specified then the generated artifact is added automatically to the list of deployables to deploy

Since your project has a packaing of type pom, it is not candidate for deployment and nothing gets deployed.

Here is an example:

  <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.0</version>
    <configuration>
      <container>
        <containerId>tomcat6x</containerId>
        <home>C:\tools\apache-tomcat-6.0.26</home>
      </container>
      <configuration>
        <properties>
          <cargo.servlet.port>8082</cargo.servlet.port>
          <cargo.jvmargs>
              "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n"
          </cargo.jvmargs>
        </properties>
        <deployables>
          <!-- application to deploy -->
          <deployable>
            <groupId>com.acme</groupId>
            <artifactId>mywebapp</artifactId>
            <type>war</type>
            <properties>
              <context>acontext</context>
            </properties>
          </deployable>
        </deployables>
      </configuration>     
    </configuration>  
  </plugin>

Update:

(...) It's giving build error as below

Artifact [com.shc.obu.ca.osol:www-webapp-1.2.0:war] is not a dependency of the project. I tried 'www-webapp' and 'www' as artifact id as well but the error remained the same.

I forgot about that but it looks like Cargo expect a deployable to be a dependency of the project where Cargo is started.

And when I add the same to dependency tags, it gives some kind of cyclic reference error as below: 'The projects in the reactor contain a cyclic reference'

Which is normal. An artifact can't be a sub-module and a dependency of a given project or you get a cyclic dependency (you need a dependency to build a module which is the dependency, chicken and egg problem).

My suggestion would be to move the cargo configuration to the www module or to create a dedicated module for your functional tests (this is usually what I do) and to declare www as dependency of this module.

Pascal Thivent
Hi Pascal,Can you please help me with a sample for both the approaches which u suggested using the POM code provided above. I tried the first approach then getting some errors like plugin tag not recognised for profiles etc. and not sure how to implement the second approach. Thanks,Neeraj
Neeraj
@Neeraj: This indicates that the POM is not valid. Inside a profile, a plugin should be declared under `<profile><build><plugins><plugin>...</plugin></plugins></build></profile>`.
Pascal Thivent
@Pascal, POM is valid and I was able to move the whole build tag inside www profile but the result is same. I tried 'mvn cargo:start' and also 'mvn -Pwww cargo:start' but still my app www-webapp-1.2.0.war doesn't gets deployed or started. But if I try running the command 'mvn -Pwww cargo:deploy' (with build tag outside or inside of profile), my 'www' war file (www-webapp-1.2.0.war ) does get copies to webapps folder under cargo.
Neeraj
@Pascal: But one thing which I can do as of now is run 'mvn cargo:start' from different window and run 'mvn cargo:deploy' from other window which is making it work for now.Thanks
Neeraj