views:

35

answers:

1

I am migrating from Maven's jetty plugin to the Cargo plugin (cargo-maven2-plugin) because Cargo will happily run WARs from dependent Maven modules. Within out web-app we have taken great pains to externalize all configuration through JNDI. These JNDI definitions are web-app specific and therefore are placed in a jetty-env.xml file that is outside the WAR. Using the Jetty plugin, we specified this file as follows:

        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <configuration>
                <jettyEnvXml>${basedir}/target/config/jetty-env.xml</jettyEnvXml>
            </configuration>
        </plugin>

How does one go about specifying this within the Cargo Plugin? Here's the configuration I have so far. It is, of course, failing because of the absent JNDI configuration:

        <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>jetty6x</containerId>
                        <type>embedded</type>
                    </container>
                    <configuration>
                        <deployables>
                            <deployable>
                                <groupId>com.mycompany</groupId>
                                <artifactId>my-war-module</artifactId>
                                <type>war</type>
                                <properties>
                                   <context>/</context>
                                </properties>
                            </deployable>
                        </deployables>
                    </configuration>
                    <wait>false</wait>
                </configuration>
                <executions>
                           ......
                </executions>
        </plugin>
+1  A: 

According to CARGO-804, Cargo's Jetty deployer now supports embedding a jetty-env.xml inside your war (as of version 1.0.3).

And in order to keep the jetty-env.xml outside your "real" war, my suggestion would be to create an additional war module to host the jetty-env.xml file and configure Cargo to merge WAR files (pay a special attention to the <extensions>true</extensions> element which is important, as mentioned in CARGO-524).

Pascal Thivent
It certainly looks like I could put the jetty-env.xml in the WEB-INF directory, but I wouldn't want to ship a WAR to customers with that file in there. I was hoping to avoid the creation of another Maven module whose existence was only to act as a server for integration test other Maven modules. Thought maybe some combination of system properties or command line arguments or something could have avoided it.
HDave
@HDave: Yes, I understand that you want to keep the jetty-env.xml outside the WAR which is why I suggested the merge approach. But I also understand that creating another module just for the purpose of Cargo might not be desired. That's the only solution I could think of though. Let's see if you find something better.
Pascal Thivent
@Pascal - After some limited, but careful study, I believe your work-around of creating another Maven module is the only approach that can work at this time. I have created a enhancement request here, which summarizes the details:
HDave
http://jira.codehaus.org/browse/CARGO-861
HDave
@HDave Voted up and watching the issue. Maybe someone will post a better alternative...
Pascal Thivent
@Pascal - I have just discovered that the patch associated with CARGO-861 was only for the Jetty Installed deployer (Jetty6xInstalledLocalDeployer) and not the embedded deployer (Jetty6xEmbeddedLocalDeployer). The result being that putting the jetty-env.xml file in the WAR file does not work unless I switch over to the installed deployer. I was trying to avoid this. In order to keep to a totally portable build environment, I'll need to use cargo to install Jetty locally before running. I created another issue for this http://jira.codehaus.org/browse/CARGO-862
HDave
@HDave: Ah, yes, I missed that point. As a side note, you could maybe use the `<zipUrlInstaller>`, see the [Tips](http://cargo.codehaus.org/Maven2+Plugin+Tips), to avoid loosing portability (never tried with Jetty). Of course, fixing your issue would be nicer.
Pascal Thivent
@Pascal - Used zipUrlInstaller and it worked. Note however that I was getting a UserTransaction class not found error until I added the JTA 1.1 depenedency to the container within cargo. I really have no idea why I had to do this, but once I got passed that error everything Just Worked.
HDave
@HDave: Good! Not sure about the JTA dependency but I guess it's the way to have Cargo putting it on the classpath when starting Jetty. Maybe a bit overcomplicated, but at least it works.
Pascal Thivent