2010-01-16 60 views
6

我的目标是有我的Ant构建脚本构建WAR文件,包括常春藤知道这个项目依赖于罐子。目前我能想到的最好的代码如下如何使用常春藤建立与复制出罐战争到lib目录

<mkdir dir="dist/lib"/> 
<ivy:retrieve pattern="dist/lib/[artifact].[ext]" sync="true"/> 
<war destfile="dist/${ivy.module}.war" basedir="build" includes="**/*.class" 
    webxml="${war.webxml}"> 
    <fileset dir="${war.web}"/> 
    <lib dir="dist/lib"/> 
</war> 

这个代码的问题是它复制罐子两次。一旦进入我的dist/lib目录并在创建时再次进入战争。它的工作原理,但我不能动摇有更好的方式的感觉。

我希望做更多的东西像下面

<ivy:cachepath pathid="locpathref.classpath"/> 
<war destfile="dist/${ivy.module}.war" basedir="build" includes="**/*.class" 
    webxml="${war.webxml}"> 
    <fileset dir="${war.web}"/> 
    <lib refid="locpathref.classpath"/> 
</war> 

的问题是,LIB标签不以任何类型的REFID服用。任何想法或我坚持一套额外的文件副本?

+0

使用<常青藤:cachefileset SETID = “locpathref.classpath” CONF =“运行“/>则LIB标签将如预期 – 2010-03-24 21:15:57

回答

4

的这里的问题是,LIB标签是一个自定义文件集靶向它的文件到战争档案的LIB子目录。这也许可以写一个自定义战争的任务,但我不认为这是值得的。

如果想提高在常春藤管理你的战争的依赖关系的方式我可能会建议使用的配置?

创建一个配置描述运行时的依赖关系:

<ivy-module version="2.0"> 
    <info organisation="apache" module="hello-ivy"/> 
    <configurations> 
     <conf name="build" description="Libraries needed to for compilation"/> 
     <conf name="war" extends="build" description="Libraries that should be included in the war file" /> 
    </configurations> 
    <dependencies> 
     <dependency org="commons-lang" name="commons-lang" rev="2.0" conf="build->*,!sources,!javadoc"/> 
     <dependency org="commons-cli" name="commons-cli" rev="1.0" conf="build->*,!sources,!javadoc"/> 
    </dependencies> 
</ivy-module> 

之后您检索它们放入一个专用目录(使用模式),可以使用战争任务的LIB标签简单地包括:

<ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]"/> 

    <war destfile="${war.file}" webxml="${resources.dir}/web.xml"> 
     <fileset dir="${resources.dir}" excludes="web.xml"/> 
     <lib dir="${lib.dir}/war"/> 
    </war> 

这种方法的好处是,你使用的常春藤每个的conf属性项目依赖性来最终决定jar是否被包含在war文件中。构建文件不再关心。

最后,我明白你的帖子的一点是你的jar文件的多个副本的关注......用我建议的方法将进一步多个复印件,但我会提出,这是不是你有一个提供问题干净目标将其删除后。

+0

我同意这是一个更好的解决方案,我正在做的又是什么,但它仍然无法删除多余的文件副本,我想。我越看越这个,我认为越多,就像你说的那样,唯一真正的解决方法就是为战争任务创建一个自定义战争任务,甚至是一个新的自定义库任务。在完美的世界中,这项新任务可能会成为常春藤或蚂蚁的一部分。 – AmaDaden 2010-01-24 15:44:26

+2

您需要的解决方案是使用常青藤cachefileset任务而不是cachepath。然后warfile的lib标签的refid参数将按预期工作 – 2010-03-24 21:22:07

4

如果你正在使用Ant 1.8,您可以使用这里描述的技术: http://www.beilers.com/2010/06/ivy-dependency-management-lessons-learned-and-ant-1-8-mapped-resources/

例:

<war destfile="${war.full.path}" webxml="WebContent/WEB-INF/web.xml" manifest="${manifest.path}"> 
    <fileset dir="WebContent"> 
    </fileset> 
    <classes dir="${build.dir}"/> 

    <mappedresources> 
     <restrict> 
     <path refid="classpath.CORE"/> 
     <type type="file"/> 
     </restrict> 
     <chainedmapper> 
     <flattenmapper/> 
     <globmapper from="*" to="WEB-INF/lib/*"/> 
     </chainedmapper> 
    </mappedresources> 

    <zipfileset dir="src" prefix="WEB-INF/classes"> 
     <include name="**/resources/**/*.properties" /> 
     <include name="**/resources/**/*.xml" /> 
    </zipfileset> 
</war> 
+0

非常有趣...我会尝试这个并报告! – 2011-03-15 15:35:54

相关问题