2007年6月1日 星期五

(2005.8月號-139期)_為企業導入開放原始碼解決方案_建構企業專案-使用Maven(1)



為企業導入開放原始碼解決方案

建構企業專案-使用Maven


序言

整合式開發環境,簡稱IDE,在專案中常用的開發系統,對於編輯、偵錯、編譯來說,IDE都很容易操作。

而隨著專案逐漸擴大,對於IDE開發工具的限制就愈來愈明顯。例如:我們很難在IDE的建置環境中使用測試和佈署。再者,將個人的IDE設定轉換給其他的開發人員亦相對的困難。




在本篇文章中,筆者將討論Apache Jakarta Project上的二大專案建置工具AntMaven,並且直接以實作來表達出,AntMaven的差異性,供開發人員在未來的專案中選擇建置工具的考量。


理論是實作的基礎,而實作鞏固理論的正確性並加深對理論的觀念,因此在以下內容中我們將以實作JPetStoreSample建置於AntMaven之上並且在關鍵處帶入重要的觀念。


列表01-開發工具:

J2SE Ver 1.4.2_08 SDKhttp://java.sun.com/j2se/index.jsp

Servlet Container(Tomcat Ver5.0.28)http://jakarta.apache.org/tomcat/index.html

Maven Ver1.0.2http://maven.apache.org/

SpringFramework Ver1.1.5http://www.springframework.org/


使用ANT建構JPetStore專案

AntAnother Neat Tool的縮寫,並且為Java基礎的建置工具,可用於小型的個人專案,亦可用於大型、多人協同開發的軟體專案。目前在許多實際上線的專案的建置、坊間書籍、雜誌上所提供的範例程式碼,大多數都有提供Ant build.xml的檔案。


這一節的實作中我們下載了spring-framework 這個project,並以這個專案中的JPetStore Sample作為與下節Maven建置專案比較範例。在本篇文章中spring-framework並不是我們要討論的重點,在此各位讀者只需了解

SpringFramework是基於IoC(控制反轉) Dependency Injection(依賴注射)觀念建置的輕量級J2EE框架即可。筆者將於往後的文章中探討Spring的使用。


在本例中將spring-framework-1.1.5-with-dependencies的版本,解壓縮後資料結構如

列表02

spring-framework-1.1.5

+--dist Spring Framework建置完成的所有jar

+--docs 說明文件

+--lib 若下載的為with-dependencies.zip,則會包含lib,為Spring相依的jar

+--mock Spring所使用的Mock Object

+--samples 使用Spring Framework建置的Sample

+--src 原始碼

+--test Unit Test的原始碼


實作範例位於samples/jpetstore 下,資料結構如

列表03

jpetstore

+--client JPetStore使用WebService測試Client

+--db 在這個Sample支援多種資料庫,預設使用HSQLDB

+--src 範例原始碼

+--war 未封裝前war檔資料放置路徑

這個JPetSetore的是個能夠正常執行的Web應用程式。

我們試著在Dos Console下執行jpetstore路徑下的build.bat則呈現以下訊息。

Buildfile: build.xml


usage:


[echo] Spring JPetStore build file

[echo] ------------------------------------------------------


[echo] Available targets are:


[echo] clean --> Clean output dirs

[echo] build --> Compile main Java sources and copy libraries

[echo] warfile --> Build the web application archive

[echo] all --> Clean, build, warfile



BUILD SUCCESSFUL

Total time: 0 seconds

從以上的訊息可知當我們執行build all之後會將JPetStore建置完成。

在此我們執行build all

Buildfile: build.xml


clean:


build:

[mkdir] Created dir: D:JProjectspring-framework-1.1.5samplesjpetstore.classes

[javac] Compiling 73 source files to D:JProjectspring-framework-1.1.5samplesjpetstore.classes

[javac] Note: Recompile with -deprecation for details.

[copy] Copying 7 files to D:JProjectspring-framework-1.1.5samplesjpetstore.classes

[mkdir] Created dir: D:JProjectspring-framework-1.1.5samplesjpetstorewarWEB-INFlib

[jar] Building jar: D:JProjectspring-framework-1.1.5samplesjpetstorewarWEB-INFlibjpetstore.jar

[copy] Copying 22 files to D:JProjectspring-framework-1.1.5samplesjpetstorewarWEB-INFlib

[copy] Copying 1 file to D:JProjectspring-framework-1.1.5samplesjpetstoreclient


warfile:

[mkdir] Created dir: D:JProjectspring-framework-1.1.5samplesjpetstoredist

[war] Building war: D:JProjectspring-framework-1.1.5samplesjpetstoredistjpetstore.war


all:


BUILD SUCCESSFUL

Total time: 5 seconds

由以上訊息得知,jpetstore.war檔建置完成。

接下來進行Deploy動作,首先啟動Tomcat,接著我們啟動JPetStore所使用的資料庫(本例使用HSQLDB),於samples/jpetstore/db/hsqldb 下執行server.bat,啟動HSQLDB Server模式。

D:JProjectspring-framework-1.1.5samplesjpetstoredbhsqldb>java -classpath .

.......libhsqldbhsqldb.jar org.hsqldb.Server -database jpetstore

[Server@1d5550d]: [Thread[main,5,main]]: checkRunning(false) entered

[Server@1d5550d]: [Thread[main,5,main]]: checkRunning(false) exited

[Server@1d5550d]: Startup sequence initiated from main() method

[Server@1d5550d]: Loaded properties from [D:JProjectspring-framework-1.1.5sam

plesjpetstoredbhsqldbserver.properties]

[Server@1d5550d]: Initiating startup sequence...

[Server@1d5550d]: Server socket opened successfully in 15 ms.

[Server@1d5550d]: Database [index=0, id=0, db=file:jpetstore, alias=] opened suc

essfully in 547 ms.

[Server@1d5550d]: Startup sequence completed in 562 ms.

[Server@1d5550d]: 2005-05-10 17:59:06.158 HSQLDB server 1.7.2 is online

[Server@1d5550d]: To close normally, connect and execute SHUTDOWN SQL

[Server@1d5550d]: From command line, use [Ctrl]+[C] to abort abruptly

最後將 jpetstore/dist/jpetstore.war 複製於 %TOMCAT_HOME%/webapps 下,Tomcat即自動進行war檔案解壓縮並完成佈署。


開啟瀏覽器鍵入http://localhost:8080/jpetstore/ 即可進入JPetStoreDemo畫面。

01

02

03

我們從剛剛的操作可以了解到使用Ant真的可以很輕易的在命令列模式中下建置出我們所需的專案,但,他真的是這麼容易的嗎?我們來看一下ANT所需的build.xml檔內容

設定01-jpetstore/build.xml

001<?xml version="1.0"?>

002

003<project name="jpetstore" basedir="." default="usage">

004

005 <property name="name" value="jpetstore"/>

006

007 <property name="war.dir" value="war"/>

008 <property name="src.dir" value="src"/>

009 <property name="client.dir" value="client"/>

010 <property name="build.dir" value=".classes"/>

011 <property name="weblib.dir" value="${war.dir}/WEB-INF/lib"/>

012 <property name="dist.dir" value="dist"/>

013

014 <property name="spring.root" value="../.."/>

015

016

017 <path id="master-classpath">

018

019 <fileset dir="${spring.root}/lib/aopalliance">

020 <include name="aopalliance.jar"/>

021 </fileset>

022 <fileset dir="${spring.root}/lib/axis">

023 <include name="axis.jar"/>

024 </fileset>

025 <fileset dir="${spring.root}/lib/ibatis">

026 <include name="ibatis-common-2.jar"/>

027 <include name="ibatis-sqlmap-2.jar"/>

028 </fileset>

029 <fileset dir="${spring.root}/lib/j2ee">

030 <include name="jaxrpc.jar"/>

031 <include name="jdbc2_0-stdext.jar"/>

032 <include name="servlet-api.jar"/>

033 </fileset>

034 <fileset dir="${spring.root}/lib/jakarta-commons">

035 <include name="commons-logging.jar"/>

036 </fileset>

037 <fileset dir="${spring.root}/lib/struts">

038 <include name="struts.jar"/>

039 </fileset>

040 <fileset dir="${spring.root}/dist">

041 <include name="spring.jar"/>

042 </fileset>

043

044 </path>

045

046

047 <target name="usage">

048

049 <echo message=""/>

050 <echo message="Spring JPetStore build file"/>

051 <echo message="------------------------------------------------------"/>

052 <echo message=""/>

053 <echo message="Available targets are:"/>

054 <echo message=""/>

055 <echo message="clean --> Clean output dirs"/>

056 <echo message="build --> Compile main Java sources and copy libraries"/>

057 <echo message="warfile --> Build the web application archive"/>

058 <echo message="all --> Clean, build, warfile"/>

059 <echo message=""/>

060

061 </target>

062

063

064 <target name="clean" description="Clean output dirs (build, weblib, dist)">

065

066 <delete dir="${build.dir}"/>

067 <delete dir="${weblib.dir}"/>

068 <delete dir="${dist.dir}"/>

069 <delete file="client/${name}.jar"/>

070

071 </target>

072

073

074 <target name="build" description="Compile main source tree java files into class files, generate jar files">

075

076 <mkdir dir="${build.dir}"/>

077

078 <javac destdir="${build.dir}" source="1.3" target="1.3" debug="true""

079 deprecation="false" optimize="false" failonerror="true">

080 <src path="${src.dir}"/>

081 <classpath refid="master-classpath"/>

082 </javac>

083

084 <copy todir="${build.dir}" preservelastmodified="true">

085 <fileset dir="${src.dir}">

086 <include name="**/*.xml"/>

087 </fileset>

088 </copy>

089

090 <mkdir dir="${weblib.dir}"/>

091

092 <jar jarfile="${weblib.dir}/${name}.jar" compress="true" basedir="${build.dir}"/>

093

094 <copy todir="${weblib.dir}" preservelastmodified="true">

095 <fileset dir="${spring.root}/lib/aopalliance">

096 <include name="aopalliance.jar"/>

097 </fileset>

098 <fileset dir="${spring.root}/lib/axis">

099 <include name="axis.jar"/>

100 <include name="saaj.jar"/>

101 <include name="wsdl4j.jar"/>

102 </fileset>

103 <fileset dir="${spring.root}/lib/caucho">

104 <include name="burlap*.jar"/>

105 <include name="hessian*.jar"/>

106 </fileset>

107 <fileset dir="${spring.root}/lib/hsqldb">

108 <include name="hsqldb.jar"/>

109 </fileset>

110 <fileset dir="${spring.root}/lib/ibatis">

111 <include name="ibatis-common-2.jar"/>

112 <include name="ibatis-sqlmap-2.jar"/>

113 </fileset>

114 <fileset dir="${spring.root}/lib/j2ee">

115 <include name="jaxrpc.jar"/>

116 <include name="jstl.jar"/>

117 </fileset>

118 <fileset dir="${spring.root}/lib/jakarta-commons">

119 <include name="commons-beanutils.jar"/>

120 <include name="commons-collections.jar"/>

121 <include name="commons-dbcp.jar"/>

122 <include name="commons-digester.jar"/>

123 <include name="commons-discovery.jar"/>

124 <include name="commons-logging.jar"/>

125 <include name="commons-pool.jar"/>

126 <include name="commons-validator.jar"/>

127 </fileset>

128 <fileset dir="${spring.root}/lib/jakarta-taglibs">

129 <include name="standard.jar"/>

130 </fileset>

131 <fileset dir="${spring.root}/lib/struts">

132 <include name="struts.jar"/>

133 </fileset>

134 <fileset dir="${spring.root}/dist">

135 <include name="spring.jar"/>

136 </fileset>

137

138 </copy>

139

140 <copy file="${weblib.dir}/${name}.jar" tofile="${client.dir}/${name}.jar"/>

141

142 </target>

143

144

145 <target name="dist" depends="warfile">

146 <!--

147 Delegate to warfile target by depending on it. dist is just to offer"

148 a generic target name across all Spring sample apps that may be used"

149 for autobuilds testing."

150 -->

151 </target>

152

153

154 <target name="warfile" depends="build" description="Build the web application archive">

155

156 <mkdir dir="${dist.dir}"/>

157

158 <war warfile="${dist.dir}/${name}.war" basedir="${war.dir}" webxml="${war.dir}/WEB-INF/web.xml">

159 <include name="*"/>

160 <include name="images/**"/>

161 <include name="WEB-INF/*.*"/>

162 <include name="WEB-INF/lib/**"/>

163 <include name="WEB-INF/jsp/**"/>

164 <include name="WEB-INF/classes/**"/>

165 <exclude name="WEB-INF/web.xml"/>

166 <exclude name="**/.*"/>

167 </war>

168

169 </target>

170

171

172 <target name="all" depends="clean,build,warfile" description="Clean,build,warfile"/>

173

174</project>


這一段冗長的xml描述就是建立JPetStore Project的邏輯,而目前並無任何工具能協助我們快速建立供ANT使用的build.xml文件,也就是說若要建置如同JPetStoreProject,必須熟悉ANT,並且需先思考建置邏輯。而後將建置邏輯以ANT的描述語法來撰寫build.xml。至於這個xml中每一段的敘述為何,將在下段的Maven中作個比較。



使用MAVEN建構JPetStore專案

MavenApache的專案管理、構建、部署工具,Maven的基本概念就是專案物件模型 (Project Object ModelPOM) 描述專案的各個方面,如專案管理部分、專案依賴部分、專案建構部分、專案報告部分,也因此必須有project.xml檔記錄這些描述。雖然Ant在專案的建置、測試與佈署的過程中提供了相當大的靈活性,但卻也曝露出太多的建置細節,使對於Ant不熟悉的開發人員難以維護。


現在,我們將透過實際操作來了解Maven到底帶來了多大的方便。


安裝Maven

Maven有二種安裝方式,其一是下載Windows Installer的執行檔,另一種則是下載Maven的壓縮檔,解壓縮後設定好環境變數後即可使用,筆者將以第二種安裝方式來說明。


我們將下載的maven-1.0.2.zip解壓縮於D:Javamaven-1.0.2 中,並設定Windows環境變數亦或撰寫設定環境變數的批次檔。

設定02-setenv.bat

set MAVEN_HOME=D:Javamaven-1.0.2

set PATH=%MAVEN_HOME%bin;%PATH%

設好環境變數後執行maven,若出現以下訊息,則代表安裝正確。

__ __

| / |__ _Apache__ ___

| |/| / _` V / -_) ' ~ intelligent projects ~

|_| |___,_|_/___|_||_| v. 1.0.2


Plugin cache will be regenerated

BUILD SUCCESSFUL

Total time: 15 seconds

Finished at: Wed May 11 20:56:54 CST 2005


查詢目前可用的公共腳本

使用maven –h會顯示mavenhelp,使用maven –g則會顯示目前所能使用的Goals

Maven中所謂的goalAnttarget的意義是相同的,皆表示為執行任務,不同的是,Anttarget必須專案建置人員自行撰寫,而Maven在預設的安裝中已存在多樣不同的goal,一般稱為公共腳本。


我們執行以下Console指令並開啟goal.txt檔,maven –g > goal.txt

列表04-goal.txt

__ __

| / |__ _Apache__ ___

| |/| / _` V / -_) ' ~ intelligent projects ~

|_| |___,_|_/___|_||_| v. 1.0.2


Available [Plugins] / Goals

===========================

genapp ......................... Generate Application based on a template

jdiff .......................... Generate an api difference report between

versions

junitdoclet .................... Generate unit tests


[abbot] Run the abbot tests

editor ......................... Launch Abbot costello editor

editor-webstart ................ Launch Abbot costello editor on a webstart

application

test ........................... Run the abbot tests

test-webstart .................. Launch tests on a webstart application

中間省略

scm:cvs-checkout-project

scm:cvs-create-patch

scm:cvs-prepare-release

scm:cvs-tag-project

scm:cvs-update-project

scm:parse-connection

scm:validate

site:generate

site:init

site:run-reports

test:eclipse

tjdo:init

uberjar:init

war:init

war:load

xdoc:dump-report-settings

xdoc:register-reports


利用應用程式範本建置初始專案

由目前存在的goal中我們可以使用genapp來輔助我們建立應用程式範本。

D:JProjectjpetstore_maven>maven genapp

__ __

| / |__ _Apache__ ___

| |/| / _` V / -_) ' ~ intelligent projects ~

|_| |___,_|_/___|_||_| v. 1.0.2


Directory C:Documents and Settings[登入者帳號].mavenrepository does not exist. Attempting to create.

Attempting to download commons-jelly-tags-interaction-20030211.143817.jar.

4K downloaded

Enter a project template to use: [default]

下一步我們將以互動式的方式輸入範本名稱,預設是default,也就是一般簡單的Application結構,讀者可自行測試,而除了default外還有其他範本可用嗎?

我們來看一下在maven安裝的路徑下plugins資料夾,maven-genapp-plugin-2.2.jar也就是我們在執行genapp這個goal時所使用的plugin,有二種方式可以查看這個jar檔內容。其一使用解壓縮程式,解開jar檔,其二Maven在首次啟動時會將maven/plugins下所有的jar檔解開並放置於Maven屬性名稱為${maven.home.local}/cache 下,預設${maven.home.local}路徑為${user.home}/.maven,也就是位於C:Documents and Settings[登入者帳號].maven 底下。


在命令列的回應中觀察到以下訊息

Directory C:Documents and Settings[登入者帳號].mavenrepository does not exist. Attempting to create.

Attempting to download commons-jelly-tags-interaction-20030211.143817.jar.

也就是在執行genapp這個goal中必須依頼某個jar檔來完成任務,而在目前Maven環境中無該檔,因此Maven會嚐試從網路上進行相依檔案下載作業,並將該檔存放於本地端的儲存庫(repository)中,所以讀者必須注意到一點,使用Maven時必須與Internate連結。

到這邊讀者或許會擔心,若日後在無法連結網路的地方建置專案,是否就無法使用Maven了,這一點到無須憂心,Maven相依jar檔下載動作只會在第一次需求相依檔案不存在時進行,第二次執行時,local端的repository所需檔案已存在也就能直接使用。


話說回來genapp到底有那些template可使用呢?

位於 ${user.home}/.maven/cache 下,因此我們可以查看cache下的maven-ganapp-plugin-2.2資料夾

列表05

maven-genapp-plutin-2.2

+--plugin-resources

+--default

+--web

+--web-jstl

+--ejb

+--complex

+--struts

+--struts-jstl

+--src

到此不難猜出除了default這個template外,還有多種的範本可供使用,在此我們選擇web範本。其他選項我們皆按下Enter採用預設值,若執行無誤命令列訊息如下:

D:JProjectjpetstore_maven>maven genapp

__ __

| / |__ _Apache__ ___

| |/| / _` V / -_) ' ~ intelligent projects ~

|_| |___,_|_/___|_||_| v. 1.0.2


Directory C:Documents and SettingsJohnnyLu.mavenrepository does not exist. Attempting to create.

Attempting to download commons-jelly-tags-interaction-20030211.143817.jar.

4K downloaded

Enter a project template to use: [default]

web

Please specify an id for your application: [app]


Please specify a name for your application: [Example Application]


Please specify the package for your application: [example.web]


build:start:


genapp:

[copy] Copying 1 file to D:JProjectjpetstore_mavensrcjavaexampleweb

[copy] Copying 1 file to D:JProjectjpetstore_mavensrctestexampleweb

[copy] Copying 2 files to D:JProjectjpetstore_mavensrctest-cactusexampleweb

[copy] Copying 2 files to D:JProjectjpetstore_maven

[copy] Copying 5 files to D:JProjectjpetstore_maven

BUILD SUCCESSFUL

Total time: 34 minutes 31 seconds

Finished at: Wed May 11 23:21:42 CST 2005

並且建立以下的資料夾結構

列表06

jpetstore_maven

+--src

| +--conf 專案相關設定檔放置路徑,例:log4j.properties

| +--java 原始碼放置路徑

| +--test 單元測試原始碼放置路徑

| +--test-cactus cactus測試原始碼放置路徑

| +--webapp 其他Web應用程式檔案放置路徑,例:jspimage、其他設定檔等

|

+--build.properties.jboss 依不同平台建置所需的屬性設定檔

+--maven.xml 可自行定義的maven行為模式檔

+--project.properties 專案屬性檔

+--project.xml Project Object ModelPOM


修改初始建置專案以符合需求

將該範本去蕪存菁,除保留confjavatesttest-cactuswebapp資料夾結構與根路徑下的四個檔案外,其餘templet資料刪除。

現在這個簡易的配置還無法讓我們的Maven正常建構專案,我們先來看一下project.xml至少該有的配置。

設定03

01 <?xml version="1.0"?>

02 <project>

03 <pomVersion>3</pomVersion>

04 <groupId>專案群組ID</groupId>

05 <id>專案ID</id>

06 <currentVersion>當前版本</currentVersion>

07 <name>專案名稱</name>

08

09 <!-- 專案管理屬性 -->

10

11 <!-- 專案相依屬性 -->

12

13 <!-- 專案建構屬性 -->

14

15 <!-- 專案報告屬性 -->

16

17 </project>


  • pomVersionProject Object Model (POM)版本,這個tag目前是無用的,但必須輸入。

  • groupId:專案群組ID,舉例來說在spring-framework-1.1.5dist 底下有多個jar檔,他們的groupIdspringmaven進行install指令時,所有jar檔會置於repository/spring 目錄下

  • idcurrentVersion:為專案ID與目前版本,用於做爲產生封裝檔的檔名,格式為[id]-[version].jar,舉例來說當id=spring-corecurrentVersion=1.1.5,則當專案建置完成封裝成jar檔時檔名為spring-core-1.1.5.jar


專案管理屬性:

專案管理部分可包含的資訊有:開發組織、開發組織網址、專案網址、版本控制訊息、發佈以及問題跟蹤網址、開發者清單、郵件清單等。這個部分的tag皆是可選用的,請讀者自行測試,在此我們不另作設定。


專案相依屬性

這個部分是專案的關鍵之一

設定04

<dependencies>

<dependency>

<groupId>springframework</groupId>

<artifactId>spring-dao</artifactId>

<version>1.1.5</version>

<properties>

<war.bundle>true</war.bundle>

</properties>

</dependency>

</dependencies>

在此處的tag的意義與表「設定03」的意義相同,war.bundle代表這個相依的jar檔將bundlewar檔內。

因此上述的設定在建置專案時Maven將在local端的repository(.maven/repository/springframework/)載入spring-dao-1.1.5.jar,若local端的repository不存在該檔,將至Remoterepository下載,並在專案封裝成war檔時置於war結構的 WEB-INF/lib 下。

Maven在此解決了Ant令詬病的問題,在「設定01」的Ant build.xml檔中相依jar檔設定分散於該檔各處,且所需檔案必須與整個專案包在一起,當專案置於CVSSVN時平白浪費了不少空間,又或著在Ant中混亂的classpath設定將導致建置無預期的失敗。

Maven只需設好dependencies,而無須擔心其他問題。


專案建構屬性

專案建構屬性具體描述了原始碼、單元測試原始碼、所需相關檔案的位置。

設定05

<build>

<nagEmailAddress>turbine-maven-dev@jakarta.apache.org</nagEmailAddress>

<sourceDirectory>src/java</sourceDirectory>

<unitTestSourceDirectory>src/test</unitTestSourceDirectory>

<unitTest>

<includes>

<include>**/*Test.java</include>

</includes>

<excludes>

<exclude>**/NaughtyTest.java</exclude>

</excludes>

</unitTest>

<resources>

<resource>

<directory>src/conf</directory>

<includes>

<include>*.properties</include>

</includes>

</resource>

</resources>

</build>

目前的預設的建置已符合需求,在此不作修改。


專案報告屬性

使用<reports>這個tag,一旦專案建置完成,即會產生各種所需報告與文件,在預設的templet中並未使用,因此筆者在此也暫不說明。


了解了POM所需的屬性後將project.xml修改如下的內容。

設定06-project.xml

<?xml version="1.0" encoding="UTF-8"?>

<project>

<pomVersion>3</pomVersion>

<groupId>jpetstore_maven</groupId>

<id>jpetstore_maven</id>

<name>JPetStore Application</name>

<currentVersion>1.0</currentVersion>


<dependencies></dependencies>


<build>

<nagEmailAddress>turbine-maven-dev@jakarta.apache.org</nagEmailAddress>

<sourceDirectory>src/java</sourceDirectory>

<unitTestSourceDirectory>src/test</unitTestSourceDirectory>

<unitTest>

<includes>

<include>**/*Test.java</include>

</includes>

<excludes>

<exclude>**/NaughtyTest.java</exclude>

</excludes>

</unitTest>

<resources>

<resource>

<directory>src/conf</directory>

<includes>

<include>*.properties</include>

</includes>

</resource>

</resources>

</build>

</project>


另外開啟maven.xml並編輯成如下的內容。

設定07-maven.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns:j="jelly:core" xmlns:ant="jelly:ant" default="war"></project>

到目前為此的動作已經完成一個正常的Maven專案的建構所需的設定。

在命令下執行maven

__ __

| / |__ _Apache__ ___

| |/| / _` V / -_) ' ~ intelligent projects ~

|_| |___,_|_/___|_||_| v. 1.0.2


build:start:


war:init:


war:war-resources:

[mkdir] Created dir: D:JProjectjpetstore_maventargetxdocletwebdoclet

[mkdir] Created dir: D:JProjectjpetstore_maventargetxdocletwebdocletWEB-INF


java:prepare-filesystem:

[mkdir] Created dir: D:JProjectjpetstore_maventargetclasses


java:compile:

[echo] Compiling to D:JProjectjpetstore_maven/target/classes

[echo]

==========================================================


NOTE: Targetting JVM 1.4, classes

will not run on earlier JVMs


==========================================================



java:jar-resources:


test:prepare-filesystem:

[mkdir] Created dir: D:JProjectjpetstore_maventargettest-classes

[mkdir] Created dir: D:JProjectjpetstore_maventargettest-reports


test:test-resources:


test:compile:


test:test:


war:webapp:

[echo] Assembling webapp jpetstore_maven

[mkdir] Created dir: D:JProjectjpetstore_maventargetxdocletwebdocletWEB-INFlib

[mkdir] Created dir: D:JProjectjpetstore_maventargetxdocletwebdocletWEB-INFtld

[mkdir] Created dir: D:JProjectjpetstore_maventargetxdocletwebdocletWEB-INFclasses


war:war:

[echo] Building WAR jpetstore_maven

[jar] Building jar: D:JProjectjpetstore_maventargetjpetstore_maven.war

BUILD SUCCESSFUL

Total time: 4 seconds

Finished at: Sun May 15 10:41:52 CST 2005

執行完畢,我們可在 jpetstore_maventarget 資料夾下發現已產生jpetstore_maven.war 的檔案。



待續…

沒有留言: