Harsh Jarring with ivy

别说谁变了你拦得住时间么 提交于 2019-12-11 16:11:43

问题


Does someone happens to know if there is a way to retrieve the contents of jar libs into one single jar - so that it would be

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

with ivy and ant ) i have a cachepath or cachefileset )


回答1:


Need to combine ivy with the groovy plug-in.

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

Use ivy configurations to separate downloads into build dependencies and a collection of files to be later combined within the build.

<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:


I actully came to this decision

<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>

then we delete temp - and voila.

Besides, may be you can suggest smth about multiple projects layout in eclipse with ivyDE and ant?? I asked this question, but no one has even posted any suggestions. Sad (



来源:https://stackoverflow.com/questions/8414719/harsh-jarring-with-ivy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!