`

ant+ivy管理项目

阅读更多

一:ivy管理jar包

   1)设置ivysetting.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivysettings>
 <ivy:configure>
  <credentials host=" service ip" realm="Sonatype Nexus Repository Manager" username="deployment" passwd="deployment123" />
 </ivy:configure>
 <settings defaultResolver="defaultChain" defaultConflictManager="latest-revision" />
 <caches defaultCacheDir="d:/.ivy2" />
 <property name="nexus-public" value="http:// service ip:7002/nexus-webapp-1.8.0.1/content/groups/public/" />
 <property name="nexus-releases" value="http:// service ip:7002/nexus-webapp-1.8.0.1/content/repositories/releases/" />
 <property name="nexus-snapshots" value="http:// service ip:7002/nexus-webapp-1.8.0.1/content/repositories/snapshots/" />
 <resolvers>
  <chain name="defaultChain" checkmodified="true" changingPattern=".*SNAPSHOT">
   <ibiblio name="public" m2compatible="true" usepoms="true" root="${nexus-public}"
    pattern="[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]" />
   <ibiblio name="releases" m2compatible="true" usepoms="true" root="${nexus-releases}"
    pattern="[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]" />
   <ibiblio name="snapshots" m2compatible="true" usepoms="true" root="${nexus-snapshots}"
    pattern="[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]" />
  </chain>
 </resolvers>
</ivysettings>

 

2) 设置ivy.xml

<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
 <info organisation="com.XXX.XXX" module="projectName" />
 <configurations>
  <conf name="default" visibility="public" extends="runtime,master" />
  <conf name="master" visibility="public" />
  <conf name="compile" visibility="public" />
  <conf name="provided" visibility="public" />
  <conf name="runtime" visibility="public" extends="compile" />
  <conf name="test" visibility="private" extends="runtime" />
 </configurations>

 <dependencies defaultconfmapping="compile->compile(*),master(*);runtime->master(*),compile(*),runtime(*)">
  <!-- log4j -->
  <dependency org="log4j" name="log4j" rev="1.2.17" conf="compile;runtime" />

  <!-- httpclient -->
  <dependency org="org.apache.httpcomponents" name="httpclient" rev="4.2.5" conf="compile;runtime" />
  <dependency org="org.apache.httpcomponents" name="httpmime" rev="4.0.1" conf="compile;runtime" />
  <dependency org="org.apache.httpcomponents" name="httpcore" rev="4.1.2" conf="compile;runtime" />
  <dependency org="org.apache.httpcomponents" name="httpclient-cache" rev="4.1.2" conf="compile;runtime" />

  <!-- others -->
  <dependency org="com.google.code.gson" name="gson" rev="2.2.4" conf="compile;runtime" />
  <dependency org="net.sf.ezmorph" name="ezmorph" rev="1.0.6" conf="compile;runtime" />
  <dependency org="net.sf.json-lib" name="json-lib" rev="2.4" m:classifier="jdk15" conf="compile;runtime" />
  <dependency org="org.aspectj" name="aspectjweaver" rev="1.6.11" conf="compile;runtime" />
  <dependency org="org.apache.poi" name="poi" rev="3.9" conf="compile;runtime" />
  <dependency org="net.sourceforge.jexcelapi" name="jxl" rev="2.6.3" conf="compile;runtime" />
  <dependency org="net.sourceforge.jexcelapi" name="jxl" rev="2.6.3" conf="compile;runtime" />
  <dependency org="javax.servlet" name="servlet-api" rev="2.5" conf="compile;runtime" />
  <dependency org="org.apache.tomcat" name="jsp-api" rev="6.0.37" conf="provided->compile(*),master(*)" />
  <dependency org="jdom" name="jdom" rev="1.0" conf="compile;runtime" />
  <dependency org="com.oracle" name="ojdbc14" rev="10.2.0.4.0" conf="compile;runtime" />
  <dependency org="commons-beanutils" name="commons-beanutils-core" rev="1.8.0" conf="compile;runtime" />
  <dependency org="commons-net" name="commons-net" rev="2.0" conf="compile;runtime" />

 

  <!-- Axiom 对象模型 -->
  <dependency org="org.apache.ws.commons.axiom" name="axiom-api" rev="1.2.8" conf="compile;runtime" />
  <dependency org="org.apache.ws.commons.axiom" name="axiom-impl" rev="1.2.8" conf="compile;runtime" />

  <!-- axis2 -->
  <dependency org="org.apache.axis2" name="axis2-adb" rev="1.5" conf="compile;runtime" />
  <dependency org="org.apache.axis2" name="axis2-java2wsdl" rev="1.5" conf="compile;runtime" />

  <!-- spring -->
  <dependency org="org.springframework" name="spring-asm" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-aspects" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-aop" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-core" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-beans" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-context" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-context-support" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-jdbc" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-expression" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-orm" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-oxm" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-web" rev="3.1.4.RELEASE" conf="compile;runtime" />


  <dependency org="org.springframework" name="spring-instrument" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-jms" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-test" rev="3.1.4.RELEASE" conf="compile;runtime" />
  <dependency org="org.springframework" name="spring-tx" rev="3.1.4.RELEASE" conf="compile;runtime" />

 

  <!-- hibernate -->
  <dependency org="org.hibernate" name="hibernate-core" rev="3.6.4.Final" conf="compile;runtime">
   <exclude module="xml-apis" />
  </dependency>
  <dependency org="org.hibernate" name="hibernate-commons-annotations" rev="3.2.0.ga" conf="compile;runtime" />
  <dependency org="org.hibernate" name="hibernate-entitymanager" rev="3.6.4.Final" conf="compile;runtime" />
  <dependency org="org.hibernate" name="hibernate-ehcache" rev="3.6.4.Final" conf="compile;runtime" />

  <!--quartz  -->
  <dependency org="org.quartz-scheduler" name="quartz" rev="2.2.0" conf="compile;runtime" />

 </dependencies>
</ivy-module>

 

3)具体的ant插件安装,详情见百度,主要一点是要把ivy的两个jar包copy到ant的lib中,在eclipse中配置ant路径 。具体的jar 包可在mvn 中查询 http://mvnrepository.com/search.html

 

4)编写build.xml ant编译文件

<?xml version="1.0" encoding="UTF-8"?>
<project name="ebg-service" default="generwar" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">

 <property name="src.dir" value="${basedir}" />
 <property name="webRoot" value="${basedir}/webroot" />
 <property name="build.lib" value="${webRoot}/WEB-INF/lib" />
 <property name="build.dir" value="${basedir}/deploy" />
 <property name="build.classes" value="${build.dir}/classes" />

 <!--加载ivy文件-->
 <ivy:settings file="ivysettings.xml" />

 <target name="resolve" description="--> parse ivy.xml">
  <ivy:resolve file="ivy.xml" conf="*" />
  <ivy:cachepath pathid="ivy.libs.compile" type="jar,bundle" conf="compile,provided" />
  <ivy:cachepath pathid="ivy.libs.test" type="jar,bundle" conf="test,provided" />
  <ivy:cachepath pathid="ivy.libs.runtime" type="jar,bundle" conf="runtime" />
 </target>

 <target name="ivy-report" depends="resolve" description="--> resolve and retrieve dependencies with ivy">
  <ivy:report />
 </target>

 <!--1、删除编译target目录-->
 <target name="clean" description="delete directory">
  <echo message="clean deploy directory" />
  <delete dir="${build.dir}" />
 </target>

 <!--2、创建编译target目录-->
 <target name="init" description="create target directory" depends="clean">
  <echo message="create deploy directory" />
  <mkdir dir="${build.dir}" />
  <mkdir dir="${build.classes}" />
 </target>

 <!--3、编译java源文件-->
 <target name="compile" description="compile source files" depends="init,resolve">
  <echo message="compile source files" />

  <javac target="1.5" encoding="utf-8" debug="true" srcdir="${src.dir}" destdir="${build.classes}">
   <compilerarg value="-Xlint:unchecked" />
   <compilerarg value="-Xlint:deprecation" />
   <classpath>
    <path refid="ivy.libs.compile" />
   </classpath>
  </javac>

 </target>

 <!--4、 复制资源文件 -->
 <target name="copyRes" depends="compile" description="copy resources to classes path">
  <echo message="copy resources to classes path" />
  <copy todir="${build.classes}">
   <fileset dir="src/resources">
    <exclude name="build/" />
    <!--排除build 文件夹-->
   </fileset>
  </copy>
 </target>

 <!-- 5.复制生产环境资源文件覆盖掉原开发资源文件-->
 <target name="copyResProd" depends="copyRes" description="copy resources to classes path">
  <echo message="copy resources to classes path" />
  <copy todir="${build.classes}" overwrite="true">
   <fileset dir="src/resources/build" />
  </copy>
 </target>

 <!--6、打成WAR包-->
 <target name="generwar" depends="copyResProd">
  <echo message="generate war" />
  <war destfile="${build.dir}/${ant.project.name}.war" webxml="${webRoot}/WEB-INF/web.xml">
   <fileset dir="${webRoot}">
    <include name="**/*.jsp" />
    <include name="**/*weblogic.xml" />
   </fileset>

   <classes dir="${build.classes}" />
   <mappedresources>
    <restrict>
     <path refid="ivy.libs.runtime" />
     <type type="file" />
    </restrict>
    <chainedmapper>
     <flattenmapper />
     <globmapper from="*" to="WEB-INF/lib/*" />
    </chainedmapper>
   </mappedresources>
  </war>

  <echo message="clean deploy directory" />
  <delete dir="${build.classes}" />
 </target>

 

</project>

 

ivy的插件自行到网上获取

 

 

0
4
分享到:
评论
4 楼 钱少少 2013-11-08  
programming 写道
和maven相比没优势

ivy只是maven中jar包管理的一部分!
3 楼 programming 2013-09-05  
和maven相比没优势
2 楼 钱少少 2013-09-04  
kingsfighter 写道
和maven相比,有什么优势?

   ivy是一个比较轻量级的版本管理,和ant组合起来就是 maven的一个替代方案,而且上手快
1 楼 kingsfighter 2013-09-04  
和maven相比,有什么优势?

相关推荐

    ant-ivy:Apache Ant Ivy的镜像

    Apache Ivy是用于管理(记录,跟踪,解决和报告)项目依赖项的工具。 它具有以下特点: 灵活性和可配置性Apache Ivy本质上与过程无关,并且不依赖于任何方法或结构。 相反,它提供了必要的灵活性和可配置性,以适应...

    pm87-agiletickets:原始的天堂

    该项目使用Ant + Ivy来构建和管理依赖项。 要获取缺少的库并完整配置项目,请在终端中运行: ant compile 第一次可能需要一段时间,因为Ivy将降低此项目的依赖关系,但下一次它应该很快。 关于该项目 AgileTickets...

    iuhyiuhkjh908u0980

    IVY,它是一个管理(记录、跟踪、解析和报告)项目依赖的工具,可与ApacheAnt紧密集成,很多的信息,请参照: http://ant.apache.org/ivy 1.代码可以从这里得到 svn co ...

    gradle-multi-project-example:Gradle多项目管理范例

    之前一直用Ant来写很多task做项目管理,配合ivy做依赖管理,不过当项目增加之后这玩意开始力不从心了,多项目采用Ant来搞的话有点自虐。 本来打算用Maven的,功能确实很强,不过它的依赖管理的写法一直让我有点犯...

    JavaBuilder:Java项目管理和构建工具,使用Java语言(适用于Java 6+)

    该工具与其他工具(例如Ant,Maven,Ivy,Gradle等)之间的主要区别在于,该构建工具使您可以直接在Java中工作。 由于您正在构建Java项目,因此可以安全地假定您已经知道Java。 另外,由于它正在运行编译的代码(而...

    pentaho-sequoiadb-plugin

    建造Pentaho SequoiaDB 插件是用 Apache Ant 构建的,并使用 Apache Ivy 进行依赖管理。 您只需使用 Ant 1.7.0 或更新版本即可开始构建项目。 如果您尚未安装 Ivy,构建脚本将下载它。 $ git clone git://github....

    gradle-7.4-all.zip 极速下载

    Gradle免费版支持maven、Ivy仓库,支持传递性依赖管理,而不需要远程仓库或者是pom.xml和ivy.xml配置文件,基于Groovy,build脚本使用Groovy编写,Gradle免费版是一个基于Apache Ant和Apache Maven概念的项目自动化...

    EclipseFolderClasspath:这是一个 Eclipse 插件,允许创建动态类路径容器,该容器观察文件夹并将所有 .jar(或 .zip 等)文件加载到类路径中。 此插件有助于使用一个文件夹中的一堆 jar 文件作为类路径,而无需手动设置

    对于不使用(有缺陷的)IvyDE 插件的 IVY 项目,有一个 ANT 或手动构建将 jar 文件检索到一个或多个文件夹中,并且这些文件夹中的所有库都需要由 eclipse 自动获取 我们开始在这个插件上投入时间,因为我们想摆脱...

    Gradle实战入门教程-整合版

    Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建开源工具。它使用一种基于Groovy的特定领域语言(DSL)来声明项目设置,目前也增加了基于Kotlin语言的kotlin-based DSL,抛弃了基于XML的各种繁琐配置。...

    积分java源码-gradle-pluralsight:使用Pluralsight学习Gradle

    Ivy 或 Maven 进行依赖管理 支持多项目构建 可以构建 Java 项目以外的东西,例如 JavaScript 或 C++ 高度可定制 声明性构建语言(表达意图) 我们告诉 Gradle 我们希望发生什么,而不是如何发生 使构建脚本比 Ant 或...

    积分java源码-gradle-fundamentals:多元视觉课程

    Ivy 或 Maven 进行依赖管理 支持多项目构建 可以构建 Java 项目以外的东西,例如 JavaScript 或 C++ 高度可定制 声明性构建语言(表达意图) 我们告诉 Gradle 我们希望发生什么,而不是如何发生 使构建脚本比 Ant 或...

    新版Android开发教程.rar

    o Apache Ant 1.6.5 or later for Linux and Mac, 1.7 or later for Windows o Not Not Not Not compatible with Gnu Compiler for Java (gcj) Note: Note: Note: Note: If JDK is already installed on your ...

Global site tag (gtag.js) - Google Analytics