沉睡森林@漂在北京

本处文章除注明“转载”外均为原创,转载请注明出处。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  152 随笔 :: 4 文章 :: 114 评论 :: 0 Trackbacks

    目前在网上能够看到的关于Maven的教程大多是一些基本的设置,但是用于一个完整的项目开发的并不是很多(如果大家有,欢迎回复),只能自己一点点整了。

    1、安装Maven2.0.4;
    2、运行mvn;
         这个主要是为了能够在%user_profile%/目录下创建.m目录。这个目录是maven的默认工作目录。
    3、创建一个基本的eclipse项目;
         mvn archetype:create -DgroupId=org.powersoft -DartifactId=app
         mvn eclipse:eclipse
    4、创建一个webapp;
         mvn archetype:create -DgroupId=org.powersoft -DartifactId=hrms -DarchetypeArtifactId=maven-archetype-webapp
    5、将生成的src/main下的webapp目录拷贝到在第3步中创建的eclipse项目中的src/main目录下;
         这个将作为web的根目录
    6、将以上创建的项目导入到eclisep工程中;
    7、由于我们将在项目使用Spring,hibernate和xfire,修改pom.xml文件
          <project xmlns="http://maven.apache.org/POM/4.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>org.powersoft</groupId>
 <artifactId>hrms</artifactId>
 <packaging>war</packaging>
 <name>Maven Quick Start Archetype</name>
 <version>1.0-SNAPSHOT</version>
 <url>http://maven.apache.org</url>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
  <!--
  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate</artifactId>
   <version>3.2.0.cr5</version>
  </dependency>    
  -->
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring</artifactId>
   <version>2.0</version>
  </dependency>
  <dependency>
   <groupId>org.codehaus.xfire</groupId>
   <artifactId>xfire-aegis</artifactId>
   <version>1.2.2</version>
  </dependency>
  <dependency>
   <groupId>org.codehaus.xfire</groupId>
   <artifactId>xfire-core</artifactId>
   <version>1.2.2</version>
  </dependency>
  <dependency>
   <groupId>org.codehaus.xfire</groupId>
   <artifactId>xfire-annotations</artifactId>
   <version>1.2.2</version>
  </dependency>
  <dependency>
   <groupId>org.codehaus.xfire</groupId>
   <artifactId>xfire-spring</artifactId>
   <version>1.2.2</version>
  </dependency>
  <dependency>
   <groupId>org.codehaus.xfire</groupId>
   <artifactId>xfire-xmlbeans</artifactId>
   <version>1.2.2</version>
  </dependency>
 </dependencies>
 
 <build>
  <plugins>
   <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <configuration>
     <scanIntervalSeconds>10</scanIntervalSeconds>
     <contextPath>/hrmsweb</contextPath>
        <systemProperties>
           <systemProperty>
                <name>org.apache.commons.logging.Log</name>
                <value>org.apache.commons.logging.impl.SimpleLog</value>
           </systemProperty>
         </systemProperties>
    </configuration>
   </plugin>
  </plugins>
 </build>
</project>
    8、在eclipse中启用maven2的plugin,将会看到一些jar在下载,可以喝咖啡去了
9、运行mvn jetty:run,将启动jetty web server。
          这样你就可以跟往常使用eclipse开发项目一样,编写类了,这个jetty插件会自动检测代码修改,并重新部署应用。
posted on 2009-07-07 17:24 王总兵 阅读(2517) 评论(1)  编辑  收藏 所属分类: Other

评论

# re: [转]利用Maven开发webapp 2009-07-07 17:25 王兵
使用Maven进行Java的web开发,Jetty Plugin是必不可缺的插件,可以极大的提到开发效率。但在Windows环境下会遇到静态文件(html、css、js)被锁定、无法即时更新的问题。要想更新这些文件,只能先停掉Jetty,保存修改,再启动Jetty,非常不方便。
解决办法是这样的:
1、从jetty.jar中解出webdefault.xml(位于org.mortbay.jetty.webapp包下)这个文件,把这个useFileMappedBuffer参数设为false
<init-param>
<param-name>useFileMappedBuffer</param-name>
<!-- change to false -->
<param-value>true</param-value>
</init-param>

2、把修改后的webdefault.xml文件跟pom.xml放在一起
3、修改pom.xml里的Jetty Plugin的配置,加入webdefault.xml
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.7</version>
<configuration>
<contextPath>/</contextPath>
<webDefaultXml>webdefault.xml</webDefaultXml>
...
</configuration>
...
</plugin>
...
  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: