【问题标题】:how to public static content with jetty-maven-plugin?如何使用 jetty-maven-plugin 公开静态内容?
【发布时间】:2016-07-08 01:01:25
【问题描述】:

我目前正在 Tomcat 中运行一个应用程序,我希望它在 Jetty 中运行它。

我的Tomcat配置如下:

  • 1战
  • 1 个暴露图像的模块

我的 Tomcat 的 server.xml 的一些代码:

<Service name="Catalina">
    <Executor maxThreads="300" minSpareThreads="50" name="tomcatThreadPool" namePrefix="tomcat-http--"/>
    <Engine defaultHost="localhost" name="Catalina">
        <Realm className="org.apache.catalina.realm.LockOutRealm">
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
        </Realm>
        <Host appBase="webapps" autoDeploy="true" deployOnStartup="true" deployXML="true" name="localhost" unpackWARs="true">
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>
            <Context docBase="/home/neuquino/svn_co/FrameworkIMG/img" path="/img" reloadable="true"/>
            <Context docBase="myapp-web" path="/" reloadable="true" source="org.eclipse.jst.j2ee.server:myapp-web"/>
        </Host>
    </Engine>
    <Connector acceptCount="100" connectionTimeout="20000" executor="tomcatThreadPool" maxKeepAliveRequests="15" port="${bio.http.port}" protocol="org.apache.coyote.http11.Http11Protocol" redirectPort="${bio.https.port}"/>
</Service>

我无法在 Jetty 中重现的是这一行中配置的内容:

<Context docBase="/home/neuquino/svn_co/FrameworkIMG/img" path="/img" reloadable="true"/>

这是我的 jetty-maven-plugin 配置

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${jetty.version}</version>
            <configuration>
                <webApp>
                    <contextPath>/</contextPath>
                    <war>${basedir}/target/myapp.war</war>
                </webApp>
            </configuration>
        </plugin>
    </plugins>
</build>

不同之处是 /home/neuquino/svn_co/FrameworkIMG/img 我没有 webApp,目录只包含文件夹和文件(在本例中为图像)

所以,问题是:如何使用 Jetty 公开静态内容?

没有必要告诉我如何用maven的插件来做,如果你知道如何用一个独立的码头发行版来做这件事对我也有很大帮助!

提前致谢!

【问题讨论】:

  • 我正在使用 jetty-maven-plugin 的 v9.0.4.v20130625

标签: java maven jetty


【解决方案1】:

正如@Neuquino 自己回答的那样,解决方案就是这样,但有一个例外:最新版本的码头需要将上下文处理程序包装到特殊部分,如下所示:

        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.2.3.v20140905</version>
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <contextHandlers>
                    <contextHandler implementation="org.eclipse.jetty.server.handler.ContextHandler">
                        <contextPath>/avatar/tmp</contextPath>
                        <resourceBase>/usr/local/resources/webapp/avatar/tmp</resourceBase>
                        <handler implementation="org.eclipse.jetty.server.handler.ResourceHandler" />
                    </contextHandler>
                </contextHandlers>
                <stopPort>9966</stopPort>
                <stopKey>foo</stopKey>
                <stopWait>10</stopWait>
            </configuration>
        </plugin>

它对我有用。

【讨论】:

    【解决方案2】:

    我找到了解决办法,这里是:

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <webApp>
                        <contextPath>/</contextPath>
                        <war>${basedir}/target/myapp.war</war>
                    </webApp>
                    <contextHandler implementation="org.eclipse.jetty.server.handler.ContextHandler">
                        <contextPath>/img</contextPath>
                        <resourceBase>/home/neuquino/svn_co/FrameworkIMG/img</resourceBase>
                        <handler implementation="org.eclipse.jetty.server.handler.ResourceHandler" />
                    </contextHandler>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 1970-01-01
      • 2015-06-06
      相关资源
      最近更新 更多