`
sillycat
  • 浏览: 2492704 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

eclipseEE版本中使用ivy管理jar包

    博客分类:
  • JAVA
阅读更多
eclipseEE版本中使用ivy管理jar包

我以前一直都是使用maven2来管理项目的,这次公司同事比较热推ivy,更轻量级些。只用ivy管理jar包,打包和管理项目还是用ant。我看同事搭建起来项目的效果,的确比较方便实用(其实主要是我们都更熟悉ant,呵呵。其实用maven也就只用到了管理jar的功能)。这里记录一下同事的配置方法,以后备用。

ivy首页
http://ant.apache.org/ivy/index.html

eclipse插件地址
http://www.apache.org/dist/ant/ivyde/updatesite

项目上没有按照maven2那样建立目录了,而是这样建立的目录:
src                            java的代码目录
conf                          配置文件的目录
    -log4j.properties      log的配置
    -config.properties    项目的properties配置
test                          测试代码的目录
WebContent              我的WEB-ROOT目录
build.properties           ANT打包的属性文件  
build.xml                    ANT的配置文件,这里来打包,驱动ivy下载JAR包
ivy.xml                       IVY的jar配置文件
ivysetttings.xml           IVY的服务器地址等配置
rebel.xml                    我用到的一个不用重启TOMCAT,可以重新加载class的工具的配置文件
其实主要的是build.properties,build.xml,ivy.xml,ivysettings.xml几个配置文件,内容分别如下,
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="http://10.206.20.43:9999/nexus/content/groups/public/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
      </url>
    </chain>
</resolvers>
</ivysettings>
其中sillycat是本地私服,sccl是公司的私服,都使用的是原来maven2的nexus开源服务器。
ivy.xml是我们要管理和导入的jar包,这里只放了两个做个示例:
<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.maven.org/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>

配置就完成了,运行以下ANT命令就行了
ant war           打war包
ant resolve     准备jar包
ant clean-cache-lib   将jar包的本地cache清空,以得到相同版本号刷新版本jar
分享到:
评论
1 楼 gogopengyou 2011-12-02  
创立

相关推荐

    工程中jar包管理工具---ivy

    项目中jar包管理工具,使得jar包可以以配置文件的形式管理,避免两个工程对相同jar包的重复使用

    ivy-2.4.0.jar

    ant 构建所需要的jar包,用于jasper report的项目,因项目中需要依赖一些外部jar包,所以必须要用构建工具,ivy是构建所必须的工具包。

    hadoop-eclipse-plugin-2.10.0.jar

    必须注意对于不同的hadoop版本,` HADDOP_INSTALL_PATH/share/hadoop/common/lib`下的jar包版本都不同,需要一个个调整 - `hadoop2x-eclipse-plugin-master/ivy/library.properties` - `hadoop2x-eclipse-plugin-...

    ivy-2.4.0-API文档-中文版.zip

    赠送jar包:ivy-2.4.0.jar; 赠送原API文档:ivy-2.4.0-javadoc.jar; 赠送源代码:ivy-2.4.0-sources.jar; 赠送Maven依赖信息文件:ivy-2.4.0.pom; 包含翻译后的API文档:ivy-2.4.0-javadoc-API文档-中文(简体)版...

    ivy-2.3.0.jar

    ivy-2.3.0.jar包,我编译eclipse hadoop插件用到的

    eclipse安装配置Ivy、Ivyde插件--亲测成功,内附说明、截图、安装包

    eclipse安装配置Ivy、Ivyde插件--亲测成功,内附说明、截图、安装包 傻瓜式安装!!!

    SBT ivy2 scala构建工具jar包

    SBT ivy2 scala构建工具jar包 scala 构建工具 sbt

    ivy-2.1.0.jar

    ivy-2.1.0.jar包,我编译eclipse hadoop插件用到的

    ivy-2.5.0.jar

    ivy-2.5.0.jar

    ivy-1.4.1.jar

    ivy 1 4 1 jar 好难找啊

    eclipse安装ivy和ivyde插件方法

    eclipse安装ivy和ivyde插件方法,内附安装过程和相应的ivy,ivyde插件安装包

    ivy-2.4.0-API文档-中英对照版.zip

    赠送jar包:ivy-2.4.0.jar; 赠送原API文档:ivy-2.4.0-javadoc.jar; 赠送源代码:ivy-2.4.0-sources.jar; 赠送Maven依赖信息文件:ivy-2.4.0.pom; 包含翻译后的API文档:ivy-2.4.0-javadoc-API文档-中文(简体)-...

    org.apache.ivy.eclipse.ant_2.4.0.final_20141213170938.jar

    org.apache.ivy.eclipse.ant_2.4.0.final_20141213170938.jar

    Jar包自动化管理(ant,ivy,nexus)

    NULL 博文链接:https://wuquanyin1011.iteye.com/blog/688167

    hadoop-eclipse-plugin-1.1.2.jar

    ${hadoop.root}/build/ivy/lib/Hadoop/common/commons-cli-${commons-cli.version}.jar" todir="${build.dir}/lib" verbose="true"/&gt; 改成 ${hadoop.root}/hadoop-core-${version}.jar" tofile="${build.dir}/lib/...

    ivy-2.4.0.jar中文-英文对照文档.zip

    中文-英文对照文档,中英对照文档,java,jar包,Maven,第三方jar包,组件,开源组件,第三方组件,Gradle,中文API文档,手册,开发手册,使用手册,参考手册 # 使用方法: 解压 【***.jar中文文档.zip】,再解压其中的 【***-...

    开发用jar包合集

    目前包含jar列表如下: ant-1.9.3.jar ant-launcher-1.9.3.jar asm-all-5.0.3.jar bcpg-jdk15on-1.51.jar bcprov-jdk15on-1.51.jar bndlib-2.1.0.jar bsh-2.0b4.jar commons-beanutils-1.7.0.jar commons-...

    JMeterAMQP.jar

    这是自己本机编译的JMeterAMQP.jar,放置位置为 jmeter安装目录中的lib/ext中,可用于测试rabbitmq等 以下为自己的编译方法: 源码地址:https://github.com/jlavallee/JMeter-Rabbit-AMQP 环境需求:jdk 1.8,...

Global site tag (gtag.js) - Google Analytics