配置指南:http://blog.csdn.net/ph9527/article/details/5063157
1、Jetty的配置参数
关于其他命令的更多信息请查阅Jetty文档中的mvn jetty:run page、mvn jetty:run-exploded page、mvn jetty:run-war page。
自动执行插件
有时候,例如在做集成测试时,你当然希望在测试开始时自动运行你的项目,测试完成时停止,而不只是手动的在命令行执行mvn jetty:run吧。
要做到这一点,你需要为jetty 插件创建几个<execution>脚本,并使用<daemon>true</daemon>配置选项来预防Jetty无限期运行,迫使它只在执行Maven时才运行。
像下面pom.xml片段中描述的pre-integration-test和post-integration-test 就是用来触发执行和关闭Jetty:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
注意:Maven默认都是通过org.apache.maven.plugins的groupId来查找插件的,即使这个groupId跟上面要表达的内容完全不同。为了更明确的指向这个groupId是我们需要的插件,唯一的办法就是在settings.xml也做如下设置:
<profile>
...
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
</profile>
如何通过命令行停止插件
委托Jetty插件无限期运行的目标包括run、run-war和run-exploded。你可以在视窗控制终端(如DOS窗口)使用<ctrl-c>关闭它,或者在另一个视窗控制终端使用stop目标关闭。如果你希望能使用mvn jetty:stop 执行关闭命令,则需要你在插件中配置一个特殊的端口和控制键。下面是一个例子配置:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<stopPort>9966</stopPort>
<stopKey>foo</stopKey>
</configuration>
</plugin>
开始:
mvn jetty:start
关闭:
mvn jetty:stop
2、为Maven jetty插件(maven-jetty-plugin)配置数据源
在使用jetty插件调试maven war项目时,我们可能需要为servlet容器(这里是jetty)配置一个数据源。下面介绍如何为jetty插件配置数据源。
1. 在src/main/resources目录下创建jetty-env.xml文件,用来配置数据源,文件内容如下:
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://jetty.mortbay.org/configure.dtd">
共同學習,寫下你的評論
評論加載中...
作者其他優質文章