Where is Cargo generating context XML for Jetty 6.x?
Asked Answered
P

1

1

I am trying to implement the solution mentioned in How to specify jetty-env.xml file for Maven Cargo plugin for Jetty?

However I am facing something even more fundamental: My Cargo is simply not generating any context xml.

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.2.1</version>
    <configuration>
        <!-- Container configuration -->
        <container>
            <containerId>jetty6x</containerId>
            <type>embedded</type>
        </container>
        <!-- Configuration to use with the container or the deployer -->
        <configuration>
            <properties>
                <cargo.servlet.port>${itest.webapp.port}</cargo.servlet.port>
                <cargo.jetty.createContextXml>true</cargo.jetty.createContextXml>
            </properties>
            <deployables>
                <deployable>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>myApp-web</artifactId>
                    <type>war</type>
                    <properties>
                        <context>/myApp</context>
                    </properties>
                </deployable>
            </deployables>
<!--
            <configfiles>
                <configfile>
                    <file>${project.build.outputDirectory}/jetty-env.xml</file>
                    <todir>contexts</todir>
                    <tofile>${jetty6.context}.xml</tofile>
                </configfile>
            </configfiles>
-->
        </configuration>
    </configuration>
    <executions>
        <execution>
            <id>start-container</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-container</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The basic idea is, we are providing the a custom context.xml to replace the one generated. However, when I am trying out, I cannot find any context XML generated by Cargo (Please note that I have remarked the custom config files, and with cargo.jetty.createContextXml being true)

I am not sure if it is my problem in setting causing the context not generated, or the context is generated somewhere I overlooked. I have checked under target/cargo/ and the temp directory that cargo expanded my WAR, neither place contains the context xml.

(I am using Maven 2.2.1, Cargo 1.2.1, JDK 6)

Putup answered 16/4, 2012 at 8:36 Comment(1)
This is Ali Tokmen from the CARGO team. I'm glad to announce that this is now fully documented in cargo.codehaus.org/Configuration+files+option Enjoy!Karolyn
L
0

I am not 100% sure what your problem is, but here is what cargo does on my system for Jetty6.

The directory where the Jetty installation is NOT where the runtime context and webapp files are. In my case, they are stored in the Java temp directory (i.e. java.io.tmpdir). On my Ubuntu system this is /tmp. Under this directory, there is a cargo/conf directory. Under /tmp/cargo/conf I have a contexts directory where the context.xml file is stored -- although the actual name of the file is never context.xml it is always named after the web app context.

In my case, this file is given the same name as the context I configured cargo with. Herein may lie your problem because I noticed that you did not supply a context as I do:

<deployables>
    <deployable>
       <properties>
         <!-- Web root context URL -->
         <context>${build.appserver.context}</context>
       </properties>
    </deployable>
</deployables>

Secondly, I also noticed you have commented out the section that places the context.xml file in the right place. Unless you uncomment that, this isn't going to work.

Thirdly, did you set the value of the ${jetty6.context} Maven property?

Fourthly - I think for this to work you need to use a standalone configuration of Jetty. This shouldn't be a problem as Cargo will automatically download and install it for you. See my config here:

                      <container>
                          <containerId>jetty6x</containerId>
                          <!-- Using Jetty for build portability so type != "remote". For Jetty
                              would prefer type = "embedded" but we must go with "installed" because jetty-env.xml
                              file would be ignored. See http://jira.codehaus.org/browse/CARGO-861 -->
                          <type>installed</type>
                          <zipUrlInstaller>
                              <url>http://dist.codehaus.org/jetty/jetty-6.1.26/jetty-6.1.26RC0.zip</url>
                              <installDir>${build.working}</installDir>
                          </zipUrlInstaller>
                          <dependencies>
                              <!-- The following dependencies are added to the servlet container's
                                  classpath as if they were installed by a system admin. In order to be included
                                  here, they need to be listed as dependencies in this pom.xml. -->
                              <dependency>
                                  <groupId>com.h2database</groupId>
                                  <artifactId>h2</artifactId>
                              </dependency>
                              <dependency>
                                  <groupId>com.oracle</groupId>
                                  <artifactId>ojdbc5</artifactId>
                              </dependency>
                              <dependency>
                                  <groupId>mysql</groupId>
                                  <artifactId>mysql-connector-java</artifactId>
                              </dependency>
                              <dependency>
                                  <groupId>net.sourceforge.jtds</groupId>
                                  <artifactId>jtds</artifactId>
                              </dependency>
                          </dependencies>
                      </container>
                      <!-- Do not hang and wait for a client, just do it -->
                      <wait>false</wait>
                      <configuration> <!-- Deployer configuration -->
                          <!-- Running Jetty container with type=installed (e.g. local) so
                              type != "runtime", and we are installing it during this execution for the
                              sake of portability so type != "existing" -->
                          <type>standalone</type>
                          <properties>
                              <!-- Use the port number from settings.xml -->
                              <cargo.servlet.port>${build.appserver.port}</cargo.servlet.port>
                          </properties>
                          <deployables>
                              <deployable>
                                  <properties>
                                      <!-- Web root context URL -->
                                      <context>${build.appserver.context}</context>
                                  </properties>
                              </deployable>
                          </deployables>
                          <configfiles>
                              <configfile>
                                  <file>${basedir}/target/jetty-context.xml</file>
                                  <todir>contexts</todir>
                                  <tofile>${build.appserver.context}.xml</tofile>
                              </configfile>
                          </configfiles>
                      </configuration>
Lilias answered 17/4, 2012 at 3:0 Comment(10)
The reason I remarked that two line is to check whether I can see cargo generating the context.xml even I am not providing one (and I want to see what's originally inside) but at last I cannot see that. I think I have provided context path ( <context>/myApp</context>). I may try again to see if I can find the place you mentioned about cargo/conf. Thanks so much for your helpPutup
I wonder if cargo's logic was changed... My result is, under target/, cargo directory is created, which contains configurations/jetty6x/etc/, but no contexts/. In temp directory, a directory containing the extracted war contents is created. It seems so different from your observation so I am afraid cargo has changed a lot afterwards :(Putup
I am running Maven Cargo plugin version 1.0.3, but I think I just realized what the issue is...you cannot make this work with the embedded Jetty. Try using the standalone configuration. See my revised answer.Lilias
In fact I am just about to try out Installed Jetty with automatic installer. Coz our company network is kind of restricted, I am about to try this solution with Jetty7x which installer can be downloaded as dependency. Thanks so much for your help. Wish I can get this work this time! :)Putup
I would try with Jetty6 first as we know that works. I'd also try with 1.0.3 as well with my configuration to verify everything works and then modify as needed from there one step at a time. Also feel free to upvote or check my answer if it was helpful. Good luck.Lilias
Yes, the key cause of the problem is embedded vs installed Jetty. Context are working fine now but there are other problem causing me to give up this approach (e.g. failed to get a path of war to put in context.xml in a way jetty can read, etc). However, thanks a lot for your help. I think I may go back to jetty maven plugin for the time being :( I do wish cargo can support external jetty-env out of box so that we do not need to do so much tricks like these :(Putup
@Adrian - You should not have to know the path to the war in order to put the context.xml file in the right place. The above configuration should put it into the /tmp/cargo/conf/contexts directory where the file name is the name of your context (e.g. my-web-app.xml). Jetty will automatically look there. This is important because putting these config files inside a WAR you intend to distribute is a bad idea (my guess is you already know this).Lilias
yes I have done that already. In fact I can have cargo read my supplied context.xml already. However in Jetty7x I got some classpath issue, while in Jetty6x, I faced issue in providing path of WAR in the context.xml which Jetty can recognize :( (poor Windows user) At last I am giving up Cargo for the moment and use Jetty plugin + overlay WAR as a workaround. Therefore I am not deploying those with my WAR (what I am trying to avoid too, which bring me to your article). But doubtless I will revisit the much cleaner Cargo solution once it allow providing custom jetty-envPutup
Ah - well I have not yet tried Cargo with Jetty7, but is it coming up. Hopefully this issue gets fixed soon, but it has already lingered over a year....Lilias
After I commented on the issue (jira.codehaus.org/browse/CARGO-861), I was told that there seems to be another fix that did the work (jira.codehaus.org/browse/CARGO-1083). I will definitely try that out and probably share in your original question if there is any good outcome :)Putup

© 2022 - 2024 — McMap. All rights reserved.