【问题标题】:Static content with Maven Jetty Plugin使用 Maven Jetty 插件的静态内容
【发布时间】:2011-07-01 11:08:36
【问题描述】:

如何使用 maven jetty 插件 (7.x) 提供静态内容

谢谢

【问题讨论】:

    标签: maven jetty maven-jetty-plugin


    【解决方案1】:

    将您的静态内容放在/yourStaticApp/src/main/webapp 下的任何文件夹下——比如/yourStaticApp/src/main/webapp/static 下。当您运行 Jetty 时,这些将作为 http://host:port/contextRoot/static/fileName.ext 提供


    嗯,不确定,如果可能的话。 Eclipse Jetty Maven 插件记录了一种配置静态源位置的方法,归结为上述webapps 的备用位置。

     ...
     <plugin>
        ...
        <configuration>
          <webAppSourceDirectory>${basedir}/src/staticfiles</webAppSourceDirectory>
          ...
        </configuration>
        ...
      </plugin>
      ...
    

    正如文档指出的那样:

    ——默认设置为 ${basedir}/src/main/webapp。如果您的静态源位于不同的位置,请相应地设置此参数。

    参考:http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin


    更新:经过进一步研究,我发现您实际上可以从 Jetty-maven 插件中指出 webdefault.xml 的位置;在 webdefault.xml 中,您可以配置 静态内容 位置。

    在您的 Jetty Maven 配置中,指向 wendefault.xml 的位置

      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <configuration>
         ...
          <defaultsDescriptor>/my/path/to/webdefault.xml</defaultsDescriptor>
         ...
        </configuration>
      </plugin>
    

    现在,有了webdefault.xml,您可以将这里提到的配置放入:http://docs.codehaus.org/display/JETTY/Static+Content——除了包名称已从org.mortbay.jetty...更改为org.eclipse.jetty...,见下文:

    <Configure class="org.eclipse.jetty.servlet.Context">
      <Set name="contextPath">/javadoc</Set>
      <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc/</Set>
      <Call name="addServlet">
        <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
        <Arg>/</Arg>
      </Call>
    </Configure>
    

    参考:http://wiki.eclipse.org/Jetty/Reference/webdefault.xml

    我没有测试/使用过上述内容。但让我知道,如果你得到这个工作。或者如果需要其他任何事情来完成这项工作。

    【讨论】:

    • 我不是这个意思。我的意思是用作静态内容的目录。请检查这个。我想用 maven 提供这样的解决方案。 docs.codehaus.org/display/JETTY/Static+Content
    • 它没有帮助我。我确信还有其他需要配置的东西。但我最感兴趣的是该页面上的第二种解决方案。是否可以像这样在 pom.xml 中配置 blog.markfeeney.com/2009/12/…
    【解决方案2】:

    我的 jetty.xml 中有这样的配置。我只是想更新我的问题。

     <Set name="handler">
         <New class="org.eclipse.jetty.server.handler.HandlerList">
            <Set name="handlers">
               <Array type="org.eclipse.jetty.server.Handler">
                  <Item>
                     <New class="org.eclipse.jetty.servlet.ServletContextHandler">
                        <Set name="contextPath">/static</Set>
                        <Set name="resourceBase">${static-resources-path}</Set>
                        <Call name="addServlet">
                           <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
                           <Arg>/</Arg>
                        </Call>
                     </New>
                  </Item>
               </Array>
            </Set>
         </New>
      </Set>
    

    【讨论】:

      【解决方案3】:

      这是一个适合我的配置,使用 JettyWebAppContext 上的 resourceBase 和 contextPath 值

      <plugin>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>jetty-maven-plugin</artifactId>
          <version>9.4.7.v20170914</version>
          <configuration>
              <scanIntervalSeconds>60</scanIntervalSeconds>
              <webApp>
                  <contextPath>/app</contextPath>
              </webApp>
              <contextHandlers>
                  <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                      <contextPath>/images</contextPath>
                      <resourceBase>./../../env/localhost/config/images</resourceBase>
                  </contextHandler>
              </contextHandlers>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多