解决的问题(Ant在项目中编译后打JAR包直接发布到Nexus中),Ant、 IVY不多说说这些网上都有资料说明,今天在来点干货,上码。

1、ivy.xml

   
   
   
   
  1. <ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  2.        xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"> 
  3.     <info 
  4.         organisation="com.targtime" 
  5.         module="tagedb" 
  6.         status="integration" revision="1.0"> 
  7.     info> 
  8.      
  9.     <publications> 
  10.         <artifact name="tagedb" type="jar" ext="jar" /> 
  11.     publications> 

2、ivysettings.xml

   
   
   
   
  1. xml version="1.0" encoding="UTF-8"?>   
  2. <ivysettings> 
  3.   <settings defaultResolver="nexus"/> 
  4.   <credentials host="localhost" 
  5.                       realm="Sonatype Nexus Repository Manager" 
  6.                       username="yourname" passwd="yourpwd"/> 
  7.   <property name="nexus-public" value="http://localhost:8081/nexus/content/groups/public"/> 
  8.   <property name="nexus-releases" value="http://localhost:8081/nexus/content/repositories/releases"/> 
  9.   <property name="nexus-snapshots" value="http://localhost:8081/nexus/content/repositories/snapshots"/> 
  10.   <resolvers> 
  11.     <ibiblio name="nexus" m2compatible="true" root="${nexus-public}"/> 
  12.     <ibiblio name="nexus-releases" m2compatible="true" root="${nexus-releases}"/> 
  13.     <ibiblio name="nexus-snapshots" m2compatible="true" root="${nexus-snapshots}" /> 
  14.   resolvers> 
  15. ivysettings> 

3、build.xml(重点在这里)

   
   
   
   
  1. <project default="create-jar" xmlns:ivy="antlib:org.apache.ivy.ant"> 
  2.     <property name="build.dir" value="classes" /> 
  3.     <property name="src.dir" value="src" /> 
  4.     <property name="lib.dir" value="lib" /> 
  5.     <property name="jar.name" value="tagedb" /> 
  6.     <property name="publish.revision" value="1.0" /> 
  7.      
  8.     <path id="master-classpath"> 
  9.         <fileset dir="${lib.dir}"> 
  10.             <include name="*.jar" /> 
  11.         fileset> 
  12.     path> 
  13.  
  14.     <target name="clean" description="Clean output dirs (build, weblib, dist)"> 
  15.         <echo>clean build direcho> 
  16.         <delete dir="${build.dir}" /> 
  17.         <mkdir dir="${build.dir}" /> 
  18.         <delete dir="dist" /> 
  19.         <mkdir dir="dist" /> 
  20.     target> 
  21.      
  22.      
  23.     <target name="create-jar" depends="clean"> 
  24.         <javac srcdir="${src.dir}" destdir="${build.dir}"> 
  25.             <classpath refid="master-classpath" /> 
  26.         javac> 
  27.         <jar destfile="dist/${jar.name}.jar" basedir="${build.dir}" /> 
  28.     target> 
  29.      
  30.      
  31.     <target name="prepare" description="Generate POM" depends="create-jar"> 
  32.          
  33.         <ivy:makepom ivyfile="ivy.xml" pomfile="${jar.name}.pom" /> 
  34.     target> 
  35.      
  36.      
  37.     <target name="resolve" description="retreive dependencies with ivy"> 
  38.          
  39.     <target name="retrieve" depends="resolve"> 
  40.         <ivy:retrieve pattern="lib/[artifact]-[revision].[ext]" conf="default" /> 
  41.     target> 
  42.      
  43.      
  44.     <target name="publish" depends="resolve,prepare" description="Upload to Nexus"> 
  45.         <ivy:publish resolver="nexus-releases" pubrevision="${publish.revision}"> 
  46.             <artifacts pattern="dist/[artifact].[ext]" /> 
  47.         ivy:publish> 
  48.     target> 
  49.      
  50. project> 

最后用ant执行build.xml就可以再nexus中看到我们上次的jar了。

 

开发二组 Polaris(海侠)