如何配置使用jetty-maven-plugin的“重写”

时间:2011-01-13 15:42:10

标签: java jetty maven-jetty-plugin

当我按命令行使用jetty7时,请$ java -jar start.jar OPTIONS=default,rewrite etc/jetty-rewrite.xml使用rewrite org.eclipse.jetty.rewrite.handler.RewriteHandler )。
但是jetty-maven-plugin和eclipse以及m2eclipse不能使用 OPTIONS = default,重写 jetty:run

并且 ClassNotFoundException:org.eclipse.jetty.rewrite.handler.RewriteHandler 尽管我添加了

  • 插件 jetty-rewrite pom.xml
  • <jettyEnvXml>foo.xml</jettyEnvXml> pom.xml
  • library jetty-write

foo.xml 是写入配置以使用重写。

我应该如何配置jetty-maven-plugin使用jetty-rewrite?

2 个答案:

答案 0 :(得分:2)

我最近不得不解决同样的问题,让Jetty 7在Maven 3中运行并使用重写规则进行初始化。只有两个组件:pom.xml,jetty.xml

这是一个pom.xml的片段:

<profile>
    <id>jetty</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>7.2.2.v20101205</version>
                <configuration>
                    <jettyConfig>${project.basedir}/config/jetty7/jetty.xml</jettyConfig>
                    <webAppConfig>
                        <contextPath>/${project.artifactId}</contextPath>
                    </webAppConfig>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-http</artifactId>
                        <version>7.2.2.v20101205</version>
                        <type>jar</type>
                        <scope>runtime</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-rewrite</artifactId>
                        <version>7.2.2.v20101205</version>
                        <type>jar</type>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</profile>

您会注意到我们已经明确设置了Jetty配置文件。此文件必须与您正在使用的Jetty版本匹配。我们遇到了其他稳定版本的问题,因此您可以选择7.2.2.v20101205,如上所示。获得jetty.xml后,您需要在其底部添加以下代码。

<Get id="oldhandler" name="handler"/>
<Set name="handler">
    <New id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
        <Set name="handler">
            <Ref id="oldhandler" />
        </Set>
        <Set name="rewriteRequestURI">true</Set>
        <Set name="rewritePathInfo">false</Set>
        <Set name="originalPathAttribute">requestedPath</Set>
            <!-- Added for mainsite js tagging files -->
        <Call name="addRule">
            <Arg>
                <New class="org.eclipse.jetty.rewrite.handler.RedirectPatternRule">
                    <Set name="pattern">/redirect/*</Set>
                    <Set name="location">/redirected</Set>
                </New>
            </Arg>
        </Call>
    </New>
</Set>

可以在互联网上以及将打包在Jetty 7.x tar中的etc / jetty-rewrite.xml文件中轻松找到Jetty重写的语法。

答案 1 :(得分:2)

我也必须解决这个问题,并且在花了一整天的时间后才开始工作。

Lanyon的帖子让我开始但是没有相当的工作。请注意,我没有部署WAR文件,也没有web.xml,我只是提供一个内置的&#34; www&#34; 。目录

对于那些发现自己处于这种情况的人来说,这对我有用:

<profile>
<id>jetty</id>
<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.2.1.v20140609</version>
            <configuration>
                <stopPort>9966</stopPort>
                <stopKey>stopit</stopKey>
                <webAppSourceDirectory>${project.build.directory}/www</webAppSourceDirectory>
                <jettyConfig>${project.basedir}/jetty.xml,${project.basedir}/jetty-rewrite.xml</jettyConfig>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-rewrite</artifactId>
                    <version>9.2.1.v20140609</version>
                    <type>jar</type>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-http</artifactId>
                    <version>9.2.1.v20140609</version>
                    <type>jar</type>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-server</artifactId>
                    <version>9.2.1.v20140609</version>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

对我来说,最大的问题是,jettyConfig需要这两个配置文件。

我通过从这里下载(完全匹配的版本)码头分发来获得这些文件:http://download.eclipse.org/jetty/提取jar并找到&#34;等等#34; 。目录

我只修改了jetty-rewrite.xml - 上面提供的Lanyon示例规则工作得很好。