2

我目前正在 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 的插件来做到这一点,如果你知道如何使用独立的码头发行版来做到这一点,它对我也有很大帮助!

提前致谢!

4

2 回答 2

3

正如@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>

这个对我有用。

于 2014-11-14T16:42:24.930 回答
1

我找到了解决方案,这里是:

<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>
于 2013-07-31T15:49:53.483 回答