简体   繁体   English

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

[英]How do I configuration to use “rewrite” by jetty-maven-plugin

When I use jetty7 by command line, do $ java -jar start.jar OPTIONS=default,rewrite etc/jetty-rewrite.xml to use rewrite ( org.eclipse.jetty.rewrite.handler.RewriteHandler ). 当我通过命令行使用jetty7时,执行$ java -jar start.jar OPTIONS=default,rewrite etc/jetty-rewrite.xml start.jar $ java -jar start.jar OPTIONS=default,rewrite etc/jetty-rewrite.xml以使用rewriteorg.eclipse.jetty.rewrite.handler.RewriteHandler )。
But jetty-maven-plugin and eclipse and m2eclipse can't use OPTIONS=default,rewrite by jetty:run . 但是jetty-maven-plugin和eclipse和m2eclipse不能使用OPTIONS = default,jetty:run 重写

And ClassNotFoundException : org.eclipse.jetty.rewrite.handler.RewriteHandler occurs in spite of the fact that I add ClassNotFoundException:尽管我添加了一个事实,但仍发生org.eclipse.jetty.rewrite.handler.RewriteHandler

  • plugin jetty-rewrite to pom.xml 插件jetty-rewritepom.xml
  • <jettyEnvXml>foo.xml</jettyEnvXml> to pom.xml <jettyEnvXml>foo.xml</jettyEnvXml>pom.xml
  • library jetty-write . 码头写

foo.xml is written configuration to use rewrite. foo.xml是书面配置,可以使用重写。

What should I do configuration to use jetty-rewrite by jetty-maven-plugin? 我应该如何配置通过jetty-maven-plugin使用jetty-rewrite?

I had to tackle this too and finally got it working after spending an entire day on it. 我也不得不解决这个问题,并且花了整整一天时间才终于使它工作。

The post from Lanyon got me started but didn't quite work. Lanyon的帖子使我开始工作,但工作并不充分。 Note that I am not deploying a WAR file and do not have a web.xml, I am simply serving up a built "www" directory. 请注意,我没有部署WAR文件,也没有web.xml,我只是提供一个内置的“ www”目录。

For anyone else who finds themselves in this situation here's what worked for me: 对于任何发现自己处于这种情况的人,这对我有用:

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

The biggest stumbing block for me was working out that jettyConfig needed both those config files. 对我而言,最大的绊脚石是,jettyConfig需要这两个配置文件。

I got those files by downloading the (exact matching version) jetty distribution from here: http://download.eclipse.org/jetty/ Extracted the jar and found the files in the "etc" directory. 我通过从此处下载(完全匹配的版本)码头发行版获得了这些文件: http : //download.eclipse.org/jetty/提取了jar并在“ etc”目录中找到了文件。

I only modified jetty-rewrite.xml - the example rule Lanyon provided above worked perfectly. 我只修改了jetty-rewrite.xml-Lanyon提供的示例规则完美运行。

I've recently had to tackle the same issue, getting Jetty 7 to run inside Maven 3 and initialize with rewrite rules in place. 我最近不得不解决相同的问题,让Jetty 7在Maven 3中运行并使用适当的重写规则进行初始化。 There's just two components: the pom.xml, jetty.xml 只有两个组件:pom.xml,jetty.xml

Here's a snippet of pom.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>

You'll notice that we've explicitly set the Jetty configuration file. 您会注意到,我们已经明确设置了Jetty配置文件。 This file must match the version of Jetty you're using. 该文件必须与您使用的Jetty版本匹配。 We had trouble with other stable releases, and thus chose 7.2.2.v20101205 as you can see above. 我们在使用其他稳定版本时遇到了麻烦,因此选择了7.2.2.v20101205,如上所示。 Once you've obtained that jetty.xml, you'll need to add the following code to the bottom of it. 一旦获得了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>

The syntax for the Jetty rewrites can be easily found on the internet as well in the etc/jetty-rewrite.xml file that will be packaged in a Jetty 7.x tar. Jetty重写的语法可以在Internet上轻松找到,也可以在打包在Jetty 7.x tar中的etc / jetty-rewrite.xml文件中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM