【问题标题】:Harsh Jarring with ivy与常春藤的剧烈震动
【发布时间】:2011-12-08 14:11:07
【问题描述】:

是否有人碰巧知道是否有一种方法可以将 jar 库的内容检索到一个 jar 中 - 这样它就可以了

jar 1 :
     org
       smth
         new.class

jar 2 :
     org
       smth
         also.class

jar 3 :
     org
       another
         otheralso.class

that single jar:
        org
          another
            one.class
          smth
            two class

result jar :
        org
          another
            one.class
            otheralso.class
        smth
           two class
           also.class
           new.class

与常春藤和蚂蚁)我有一个缓存路径或缓存文件集)

【问题讨论】:

    标签: ant ivy


    【解决方案1】:

    需要将ivy与groovy插件结合起来。

    build.xml

    <target name="resolve">
        <ivy:resolve/>
        <ivy:cachepath pathid="build.path" conf="build"/>
        <ivy:cachefileset setid="jarfiles" conf="jars"/>
    </target>
    
    <target name="combine-jars" depends="resolve">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
    
        <!-- 
        Iterate thru each file expanding content into a temp directory
        used to create a new jar
        -->
        <groovy>
        project.references.jarfiles.each {
            ant.unzip(src: it, dest:"build/tmp")
        }
        ant.jar(destfile:"build/newjar.jar", basedir:"build/tmp")
        </groovy>
    </target>
    

    ivy.xml

    使用 ivy 配置将下载分为构建依赖项和集合 稍后在构建中合并的文件。

    <ivy-module version="2.0">
        <info organisation="org.myspotontheweb" module="demo"/>
        <configurations>
            <conf name="build" description="ANT tasks"/>
            <conf name="jars"  description="Files to be combined"/>
        </configurations>
        <dependencies>
            <!-- build dependencies -->
            <dependency org="org.codehaus.groovy" name="groovy-all" rev="1.8.2" conf="build->default"/>
    
            <!-- jars dependencies -->
            <dependency org="log4j" name="log4j" rev="1.2.16" conf="jars->default"/>
            <dependency org="commons-lang" name="commons-lang" rev="2.6" conf="jars->default"/>
            ..
            ..
        </dependencies>
    </ivy-module>
    

    【讨论】:

      【解决方案2】:

      我确实做出了这个决定

      <target name="project.archive" depends="project.make, ivy-runtimecahe">
          <mkdir dir="${project.build}\temp" />
          <copy todir="${project.build}\temp">
                            <archives>
                              <zips >
                                <restrict >
                                  <path refid="classpath.Runtime" />
                                  <name name="*.jar" />
      
                                </restrict>
      
                              </zips>
                            </archives>
      
                          </copy>
                 <jar jarfile="${project.build}\${project.archive.name}-${project.version}.jar"
               manifest="${basedir}\${project.maifest}">
          <fileset dir="${project.build}\temp" includes="**\*.class" />
          <fileset dir="${project.classes}" includes="**\*.class" />
          <fileset dir="Btlserver" includes="**\*.xml" /> 
      
             </jar>
      

      然后我们删除 temp - 瞧。

      此外,您是否可以建议在 eclipse 中使用 ivyDE 和 ant 进行多个项目布局?我问了这个问题,但没有人发表任何建议。伤心(

      【讨论】:

        猜你喜欢
        • 2013-04-26
        • 2018-07-07
        • 2013-04-11
        • 2012-01-13
        • 2012-11-16
        • 2017-08-30
        • 2011-04-12
        • 2013-01-28
        • 2023-04-03
        相关资源
        最近更新 更多