最近准备离职了,等着到20号离开。所以在公司里面没有什么事情,自己研究了一下maven。以前对他的认识主要是依赖管理,而这几天的学习,对他的plugin机制影响特别深刻。特别的是jetty插件的使用,十分方便。
首先需要下载eclipse,推荐最新的Helios版本,安装m2eclipse插件,更新地址为:http://m2eclipse.sonatype.org/sites/m2e/0.10.2.20100623-1649/。新建一个maven项目,并且使用下面的pom文件。具体代码如下:
<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>cn.gwssi</groupId>
<artifactId>gwssi-extjsptags-demo</artifactId>
<packaging>war</packaging>
<version>1.0.1-SNAPSHOT</version>
<name>gwssi-extjsptags-demo Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- J2EE相关依赖jar包 -->
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>5.0-1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>1.2_04</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.2_04</version>
<scope>provided</scope>
</dependency>
<!-- J2EE相关依赖jar包~~~~~~~~~~~~结束 -->
<!-- pojo copy (usually for webservice) -->
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
<finalName>gwssi-extjsptags-demo</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<charset>UTF-8</charset>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.1.0.RC1</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jcl</artifactId>
<version>1.0.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
在eclipse中选择菜单run-》external tools进入,配置2个命令:jetty_run和jetty_stop。其中run命令location为$MAVEN_HOME/bin/mvn.bat,working directory选择当前项目即可,参数输入:-Dslf4j=false -Dlog4j.configuration=file:./target/classes/log4j.properties jetty:run。
stop命令和run命令前面2项相同,参数输入:jetty:stop。
配置完上面的东西,你马上可以开始一个maven+jetty项目,运行run即可访问http://localhost:8080访问web页面,运行stop关闭服务器。