【问题标题】:Configure maven cargo plugin jetty container for static content为静态内容配置 maven cargo plugin jetty 容器
【发布时间】:2017-03-31 17:06:10
【问题描述】:

我需要配置从 maven cargo 插件运行的 jetty 以将其指向静态内容,我查看了 jetty 文档,但我看不到当它作为货物的一部分运行时如何将配置应用于 jetty。我想配置 webApp 部分并将资源库设置为作为此构建模块构建的我的 Angular 应用程序:

 <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 启动,但它似乎忽略了这个配置,我的 index.html 文件只得到了 404。

有人能指点我正确的方向吗?

【问题讨论】:

    标签: html maven jetty cargo


    【解决方案1】:

    虽然 cargo 似乎不直接支持 Jetty 的 reload自动热重新部署 功能,但至少您可以提供“未完成”的静态内容并立即获取更改,例如在运行嵌入式容器的开发过程中。

    我当前的解决方案是重新配置Jetty's DefaultServlet,将resourceBase 指向项目的“实时”源目录(例如${basedir}/src/main/webapp)而不是可部署的default (build) &lt;location/&gt;(例如${project.build.directory}/${project.build.finalName}),并且(只是为了请确保)disabling useFileMappedBuffer 以避免在 Windows 中锁定文件:

    1. 将 Jetty 的 webdefault.xml(例如,当独立运行货柜时,从 target/cargo/configurations/jetty.../etc/)复制到 src/main/jetty/my-webdefault.xml
    2. 修改其DefaultServlet初始化参数:

      <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. cargo-maven2-plugin copy the new config file my-webdefault.xml 放入(Jetty)容器的etc/ 目录:

      <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. 使用mvn clean verify cargo:run 运行

    PS。我尝试使用scratch.xml 在单独的上下文(例如/static)中触发简单的static content ResourceHandler,但没有成功。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-07
      • 2011-07-01
      • 1970-01-01
      • 2015-06-13
      • 1970-01-01
      • 1970-01-01
      • 2018-02-12
      相关资源
      最近更新 更多