ANT脚本将Maven Dependencies的jar包copy到WEB-INF下

ANT脚本将Maven Dependencies的jar包copy到WEB-INF下

系统之前一直用的是maven-artifact-ant-2.0.4-dep.jar,但最近对一些jar包支持不好,运行ant脚本出现以下问题:

[artifact:dependencies] [WARNING] POM for 'ch.qos.logback:logback-classic:pom:0.9.9' is invalid. It will be ignored for artifact resolution. Reason: The POM expression: ${parent.version} could not be evaluated. Reason: ch.qos.logback:logback-classic:jar:${parent.version} references itself.

这样的话这个忽略的jar包就得手动copy了,这样你还得找这个jar包依赖的其他jar包是不是存在。后来在网上google了一下,发现现在都用maven-ant-tasks-2.1.0.jar,然后对build.xml稍作改动,如下即可:
<? xml version="1.0" encoding="UTF-8" ?>
< project  name ="hehe"  default ="maven-jar"  xmlns:artifact ="urn:maven-artifact-ant" >
    
< property  file ="build.properties"   />
        
< target  name ="maven-jar"  description ="Use Maven2 to manage jars' dependencies" >
        
< echo  message ="deleting old jar .. "   />
        
< delete  dir ="${web.dir}/WEB-INF/lib"   />
        
< copy  todir ="${web.dir}/WEB-INF/lib" >
            
< fileset  id ="runtimeFiles"  dir ="lib/mylib" >
                
< include  name ="**/*.jar"   />
            
</ fileset >
            
< mapper  type ="flatten"   />
        
</ copy >
        
< echo  message ="Use Maven2 to manage jar."   />
        
< typedef  resource ="org/apache/maven/artifact/ant/antlib.xml"  uri ="urn:maven-artifact-ant" >
            
< classpath >
                
< pathelement  location ="lib/maven-ant-tasks-2.1.0.jar"   />
            
</ classpath >
        
</ typedef >

        
< artifact:pom  file ="pom.xml"  id ="my.pom"   />

        
< artifact:dependencies  pathId ="dependency.classpath"  filesetId ="dependency.fileset"  usescope ="runtime" >
            
< pom  refid ="my.pom"   />
        
</ artifact:dependencies >

        
< copy  todir ="${web.dir}/WEB-INF/lib" >
            
< fileset  refid ="dependency.fileset"   />
            
< mapper  type ="flatten"   />
        
</ copy >
    
</ target >
</ project >
这样就OK了
 

你可能感兴趣的:(ANT脚本将Maven Dependencies的jar包copy到WEB-INF下)