最近準備離職了,等著到20號離開。所以在公司里面沒有什么事情,自己研究了一下maven。以前對他的認識主要是依賴管理,而這幾天的學習,對他的plugin機制影響特別深刻。特別的是jetty插件的使用,十分方便。
首先需要下載eclipse,推薦最新的Helios版本,安裝m2eclipse插件,更新地址為:http://m2eclipse.sonatype.org/sites/m2e/0.10.2.20100623-1649/。新建一個maven項目,并且使用下面的pom文件。具體代碼如下:
在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關閉服務器。
首先需要下載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>
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關閉服務器。