2016-04-14 56 views
0

我需要配置从maven货物插件运行的jetty以将其指向静态内容,Ive浏览了码头文档并且无法看到如何将配置应用于码头作为货物的一部分运行。我要配置的Web应用程序部分,将资源基地作为我建的这个版本的模块角应用:为静态内容配置maven货物插件码头容器

<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> 

码头开始,但它似乎忽略了这个配置,我只是得到我的索引404。 html文件。

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

回答

0

虽然货物似乎并不直接支持Jetty的重装自动热部署功能,至少你可以为你的“未完成”静态内容,并立即拿起变化,例如在开发过程中运行嵌入式容器。

我目前的解决办法是重新配置Jetty's DefaultServlet指着resourceBase到项目的“活”的源代码目录(如${basedir}/src/main/webapp),而不是部署的default (build) <location/>(例如,${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-plugincopy the new config filemy-webdefault.xml到(码头)容器的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 content ResourceHandler(例如/static)的尝试没有成功。