0

I need to configure jetty running from the maven cargo plugin to point it at static content, Ive looked through the jetty documentation and I cant see how to apply the configuration to jetty when it is running as part of cargo. I want to configure the webApp section and set the resource base as my angular app built as a module of this build:

 <execution>
                  <id>start jetty - angular webapp</id>
                  <phase>pre-integration-test</phase>
                  <goals>
                    <goal>start</goal>
                  </goals>
                  <configuration>                           
                        <container>
                            <containerId>jetty7x</containerId>
                            <type>embedded</type>
                        </container>
                        <webApp>
                            <resourceBases>
                                <contextPath>/</contextPath>
                                <resourceBase>../calculator-web/dist</resourceBase>
                            </resourceBases>
                        </webApp>   
                        <configuration> 
                            <properties>                    
                                <cargo.servlet.port>11000</cargo.servlet.port>                                          
                            </properties>                               
                        </configuration>
                    </configuration>
                </execution>

Jetty starts but it seems to ignore this configuration and I just get a 404 for my index.html file.

Can somebody point me in the right direction please?

berimbolo
  • 3,319
  • 8
  • 43
  • 78

1 Answers1

0

Although cargo does not seem to support Jetty's reload or automatic hot redeploy feature directly, at least you can serve your 'unfinished' static content and immediately pick up changes, e.g. during development while running an embedded container.

My current solution is to reconfigure Jetty's DefaultServlet, pointing the resourceBase to the project's 'live' source directory (e.g. ${basedir}/src/main/webapp) rather than the deployable's default (build) <location/> (e.g. ${project.build.directory}/${project.build.finalName}), and (just to be sure) disabling useFileMappedBuffer to avoid file locking in Windows:

  1. Copy Jetty's webdefault.xml (from e.g. target/cargo/configurations/jetty.../etc/ when running the cargo container as standalone) to, for instance, src/main/jetty/my-webdefault.xml
  2. Modify its DefaultServlet initialization parameters:

    <web-app ...> <!-- src/main/jetty/my-webdefault.xml -->
      :
      <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
        :
        <init-param> <!-- relative to pom.xml, or wherever cargo runs -->
          <param-name>resourceBase</param-name>
          <param-value>./src/main/webapp</param-value>
        </init-param>
        <init-param> <!-- to avoid file locking in Windows, use: false -->
          <param-name>useFileMappedBuffer</param-name>
          <param-value>false</param-value>
        </init-param>
      </servlet>
    </web-app>
    
  3. Have the cargo-maven2-plugin copy the new config file my-webdefault.xml into the (Jetty) container's etc/ directory:

    <project ...> <!-- pom.xml -->
      :
      <build>
        :
        <plugins>
          :
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>...</version>
            <configuration>
              <container>...</container>
              <configuration>
                <configfiles>
                  <configfile>
                    <file>${basedir}/src/main/jetty/my-webdefault.xml</file>
                    <tofile>etc/webdefault.xml</tofile>
                  </configfile>
                </configfiles>
                <properties>...</properties>
              </configuration>
              <deployables>...</deployables>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
    
  4. Run with mvn clean verify cargo:run

PS. My attempts with a scratch.xml to trigger a simple static content ResourceHandler in a separate context (e.g. /static) were without success.

krevelen
  • 361
  • 3
  • 11