Wh开发者_开发问答en 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).
And ClassNotFoundException : org.eclipse.jetty.rewrite.handler.RewriteHandler occurs in spite of the fact that I add
- plugin jetty-rewrite to pom.xml
<jettyEnvXml>foo.xml</jettyEnvXml>
to pom.xml- library jetty-write.
foo.xml is written configuration to use rewrite.
What should I do configuration to use jetty-rewrite by jetty-maven-plugin?
I've recently had to tackle the same issue, getting Jetty 7 to run inside Maven 3 and initialize with rewrite rules in place. There's just two components: the pom.xml, jetty.xml
Here's a snippet of 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. This file must match the version of Jetty you're using. We had trouble with other stable releases, and thus chose 7.2.2.v20101205 as you can see above. Once you've obtained that jetty.xml, you'll need to add the following code to the bottom of it.
<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.
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. 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.
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.
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.
I only modified jetty-rewrite.xml - the example rule Lanyon provided above worked perfectly.
精彩评论