maven3 jetty jrebel 搭建可调式的开发环境

信息:maven3 jetty7.2 jrebel3.6.1

jetty是一个轻量级的container,一般和maven搭配使用,关于jrebel的作用,到网络查一查就知道了,绝对是好东西。

下面开始搭建环境,一个JSF2.0的web 应用为例

 

1首先使用eclipse建立一个web 接口的maven项目(不要告诉我你不知道怎么建)

j建好之后目录如下


接下来开始编辑pom.xml文件,文件内容如下<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Xml代码   收藏代码
  1.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  2.     <modelVersion>4.0.0</modelVersion>  
  3.     <groupId>com.study</groupId>  
  4.     <artifactId>jetty</artifactId>  
  5.     <packaging>war</packaging>  
  6.     <version>0.0.1-SNAPSHOT</version>  
  7.     <name>jetty Maven Webapp</name>  
  8.     <url>http://maven.apache.org</url>  
  9.     <repositories>  
  10.     <!-- 配置下载JSF2.0 类库的maven仓库 -->  
  11.         <repository>  
  12.             <id>java.net</id>  
  13.             <name>java.net</name>  
  14.             <url>http://download.java.net/maven/2</url>  
  15.         </repository>  
  16.     </repositories>  
  17.     <!-- JSF2.0的依赖 -->  
  18.     <dependencies>  
  19.         <dependency>  
  20.             <groupId>com.sun.faces</groupId>  
  21.             <artifactId>jsf-api</artifactId>  
  22.             <version>2.0.4-b09</version>  
  23.             <scope>compile</scope>  
  24.         </dependency>  
  25.   
  26.         <dependency>  
  27.             <groupId>com.sun.faces</groupId>  
  28.             <artifactId>jsf-impl</artifactId>  
  29.             <version>2.0.4-b09</version>  
  30.             <scope>compile</scope>  
  31.         </dependency>  
  32.   
  33.         <dependency>  
  34.             <groupId>junit</groupId>  
  35.             <artifactId>junit</artifactId>  
  36.             <version>3.8.1</version>  
  37.             <scope>test</scope>  
  38.         </dependency>  
  39.     </dependencies>  
  40.   
  41.     <build>  
  42.         <finalName>jetty</finalName>  
  43.         <plugins>  
  44.         <!-- 配置 maven 的 jetty 插件 -->  
  45.             <plugin>  
  46.                 <groupId>org.mortbay.jetty</groupId>  
  47.                 <artifactId>jetty-maven-plugin</artifactId>  
  48.                 <version>7.2.2.v20101205</version>  
  49.                 <configuration>  
  50.                     <webAppConfig>  
  51.                         <contextPath> /${project.artifactId}</contextPath>              <!--  指定 root context 在这里指定为${project.artifactId} 即 jetty,  
  52.                         那么访问时就用http://localized:8080/jetty 访问,  
  53.                         如果指定梶为test 就用http://localized:8080/test访问,更多信息,请查看jetty 插件官方文档-->  
  54.                     </webAppConfig>  
  55.                     <!-- 指定额外需要监控变化的文件或文件夹,主要用于热部署中的识别文件更新 -->  
  56.                     <scanTargetPatterns>  
  57.                         <scanTargetPattern>  
  58.                             <directory>src</directory>  
  59.                             <includes>  
  60.                                 <include>**/*.java</include>  
  61.                                 <include>**/*.properties</include>  
  62.                             </includes>  
  63.                             <!-- <excludes> <exclude>**/*.xml</exclude> <exclude>**/myspecial.properties</exclude>  
  64.                                 </excludes> -->  
  65.                         </scanTargetPattern>  
  66.                     </scanTargetPatterns>  
  67.                     <scanIntervalSeconds>0</scanIntervalSeconds><!-- 指定监控的扫描时间间隔,0为关闭jetty自身的热部署,主要是为了使用jrebel -->  
  68.                     <webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory><!-- 指定web页面的文件夹 -->  
  69.                 </configuration>  
  70.             </plugin>  
  71.   
  72. <!-- jerebel maven 插件,用于生成jrebel.xml -->  
  73.             <plugin>  
  74.                 <groupId>org.zeroturnaround</groupId>  
  75.                 <artifactId>jrebel-maven-plugin</artifactId>  
  76.                 <executions>  
  77.                     <execution>  
  78.                         <id>generate-rebel-xml</id>  
  79.                         <phase>process-resources</phase>  
  80.                         <goals>  
  81.                             <goal>generate</goal>  
  82.                         </goals>  
  83.                     </execution>  
  84.                 </executions>  
  85.                 <configuration>  
  86.                 <rebelXmlDirectory>${basedir}/src/main/webapp/WEB-INF/classes</rebelXmlDirectory><!-- 指定生成的jrebel.xml放在哪里,  
  87.                 要求放在web应用的 classpath下 -->  
  88.                 </configuration>  
  89.             </plugin>  
  90.         </plugins>  
  91.         <outputDirectory>${basedir}/src/main/webapp/WEB-INF/classes</outputDirectory><!-- 指定编译后文件的存放路径,因为jetty默认src/main/webapp为  
  92.         web应用的根目录而 maven compile 目标后的默认classpath 在target文件夹下,就造成jrebel.xml无法兼顾 jetty 默认的是webapp中的classes为 web 应用的根目录,  
  93.         而maven 默认是target 目录所以需要修改该maven的默认classes目录。 -->  
  94.     </build>  
  95. </project>  
 

 配置好后,就剩下加入jrebel的参数了。要在eclipse里加入jrebel参数,需要装jrebel for eclipse 插件,装好之后,对pom.xml点右键,选择run->run configurations,在弹出的对话框中选择标签jrebel,勾选enable jrebel agent



 确定,然后run就行了。如果要调试,就右键点击pom文件,选择debug就行。整个maven 项目已经上传,可以下载自己试试


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值