eclipseEE版本中使用ivy管理jar包 我以前一直都是使用maven2來(lái)管理項(xiàng)目的,這次公司同事比較熱推ivy,,更輕量級(jí)些,。只用ivy管理jar包,打包和管理項(xiàng)目還是用ant,。我看同事搭建起來(lái)項(xiàng)目的效果,的確比較方便實(shí)用(其實(shí)主要是我們都更熟悉ant,,呵呵,。其實(shí)用maven也就只用到了管理jar的功能)。這里記錄一下同事的配置方法,,以后備用,。 ivy首頁(yè) http://ant./ivy/index.html eclipse插件地址 http://www./dist/ant/ivyde/updatesite 項(xiàng)目上沒有按照maven2那樣建立目錄了,而是這樣建立的目錄: src java的代碼目錄 conf 配置文件的目錄 -log4j.properties log的配置 -config.properties 項(xiàng)目的properties配置 test 測(cè)試代碼的目錄 WebContent 我的WEB-ROOT目錄 build.properties ANT打包的屬性文件 build.xml ANT的配置文件,,這里來(lái)打包,,驅(qū)動(dòng)ivy下載JAR包 ivy.xml IVY的jar配置文件 ivysetttings.xml IVY的服務(wù)器地址等配置 rebel.xml 我用到的一個(gè)不用重啟TOMCAT,可以重新加載class的工具的配置文件 其實(shí)主要的是build.properties,build.xml,ivy.xml,ivysettings.xml幾個(gè)配置文件,,內(nèi)容分別如下,, ivy.settings.xml: <ivysettings> <settings defaultResolver="chained"/> <resolvers> <chain name="chained" returnFirst="true"> <filesystem name="libraries"> <artifact pattern="${ivy.conf.dir}/lib/[artifact]-[revision].[type]" /> </filesystem> <url name="sillycat"> <artifact pattern="http://localhost:8081/nexus/content/groups/public/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" /> </url> <url name="sccl"> <artifact pattern=" </url> </chain> </resolvers> </ivysettings> 其中sillycat是本地私服,sccl是公司的私服,,都使用的是原來(lái)maven2的nexus開源服務(wù)器,。 ivy.xml是我們要管理和導(dǎo)入的jar包,,這里只放了兩個(gè)做個(gè)示例: <ivy-module version="2.0"> <info organisation="sccl" module="swak" /> <configurations> <conf name="release" /> </configurations> <publications> <artifact name="common" /> <artifact name="client" /> </publications> <dependencies> <!-- commons --> <dependency org="commons-logging" name="commons-logging" rev="1.1.1"/> <!-- spring jar --> <dependency org="org/springframework" name="spring" rev="2.5.6"/> </dependencies> </ivy-module> build.properties文件,里面配置的是build的一些信息: app.name=ivysample catalina.home=D:\eclipse-company\apache-tomcat-6.0.20 ant.encoding=GBK java.level=1.5 另外就是重頭戲了,,ANT的build.xml文件 <project name="${app.name}" default="all" xmlns:ivy="antlib:org.apache.ivy.ant"> <!-- some variables used --> <property file="build.properties" /> <property name="app.name" value="${app.name}" /> <property name="src.dir" value="src" /> <property name="conf.dir" value="conf" /> <property name="build.dir" value="build" /> <property name="dist.dir" value="dist" /> <property name="web.dir" value="WebContent" /> <property name="lib.dir" value="${web.dir}/WEB-INF/lib" /> <property name="tomcat.dir" value="${catalina.home}" /> <property name="ivy.install.version" value="2.0.0" /> <property name="ivy.home" value="${user.home}/.ant" /> <property name="ivy.jar.dir" value="${ivy.home}/lib" /> <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<!-- paths used for compilation and run --> <path id="compile.path.id"> <fileset dir="${tomcat.dir}\lib" /> <fileset dir="${lib.dir}" /> <path location="${build.dir}" /> </path> <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpath="${ivy.jar.file}" /> <target name="download-ivy"> <mkdir dir="${ivy.jar.dir}" /> <get src="http://repo1./maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true" /> </target> <!-- ================================= target: resolve ================================= --> <target name="resolve" depends="download-ivy" description="--> retreive dependencies with ivy"> <ivy:retrieve pattern="${web.dir}/WEB-INF/lib/[artifact]-[revision].[ext]" /> </target> <!-- ================================= target: clean-cache ================================= --> <target name="clean-cache-lib" description="--> clean the ivy cache"> <delete dir="${ivy.home}/cache" /> </target> <!-- ================================= target: clean ================================= --> <target name="clean" description="--> clean the project"> <delete dir="${build.dir}" /> <delete dir="${dist.dir}" /> </target> <!-- ================================= target: prepare ================================= --> <target name="prepare" description="--> make-dir build , dist"> <tstamp /> <mkdir dir="${build.dir}" /> <mkdir dir="${dist.dir}" /> <echo message="built at ${DSTAMP}-${TSTAMP}" /> <echo message="ant.version - ${ant.version}" /> <echo message="ant.java.version - ${ant.java.version}" /> <echo message="ivy.cache.dir - ${ivy.home}/cache"/> </target> <!-- ================================= target: compile ================================= --> <target name="compile" depends="prepare" description="--> Compile Java sources"> <!-- Compile Java classes as necessary --> <property name="compile.java.encoding" value="${ant.encoding}" /> <mkdir dir="${build.dir}/WEB-INF/classes" /> <javac srcdir="${src.dir}" destdir="${build.dir}/WEB-INF/classes" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}" encoding="${ant.encoding}" source="${java.level}"> <classpath refid="compile.path.id" /> </javac> <copy todir="${build.dir}/WEB-INF/classes"> <fileset dir="${src.dir}"> <include name="**/*.xml"/> <include name="**/*.txt"/> <include name="**/*.properties"/> <exclude name="config.properties"/> <exclude name="log4j.properties"/> </fileset> </copy> </target> <!-- ================================= target: javadoc ================================= --> <target name="javadoc" depends="compile" description="-->Create Javadoc API documentation"> <mkdir dir="${dist.dir}/api-docs" /> <javadoc sourcepath="${src.dir}" destdir="${dist.dir}/api-docs" packagenames="*"> <classpath refid="compile.path.id" /> </javadoc> </target> <target name="copyWeb"> <copy todir="${build.dir}"> <fileset dir="${web.dir}"> <exclude name="WEB-INF/classes/**"/> </fileset> </copy> </target> <target name="war" depends="clean,compile,copyWeb" description="--> build web application war package"> <war destfile="${dist.dir}/${app.name}.war" webxml="${build.dir}/WEB-INF/web.xml"> <fileset dir="${build.dir}"/> </war> <copy tofile="${dist.dir}/config.properties" file="${conf.dir}/config.properties"/> <copy tofile="${dist.dir}/log4j.properties" file="${conf.dir}/log4j.properties"/> </target>
<target name="all" depends="war,javadoc" description="clean, build jar package, generate api- doc"> </target> </project> 配置就完成了,,運(yùn)行以下ANT命令就行了 ant war 打war包 ant resolve 準(zhǔn)備jar包 ant clean-cache-lib 將jar包的本地cache清空,以得到相同版本號(hào)刷新版本jar
|