博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ANT构建JAR包时设置MANIFEST.MF的Class-Path属性的技巧
阅读量:4349 次
发布时间:2019-06-07

本文共 1858 字,大约阅读时间需要 6 分钟。

ANT构建JAR包时设置MANIFEST.MF的Class-Path属性的技巧  

MANIFEST.MF是ANT打jar包时自动加入META-INF目录下的一个文件,上面默认记录了Manifest-Version、Ant-Version、Created-By等属性信息,如:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.5.0-b64 (Sun Microsystems Inc.)
当jar包中的class文件引用了第三方类库时,就要在Class-Path属性中写入这些类库的引用路径,注意,这个路径是相对于第一层Archive来说的。如你把第三方的jar包都放到了你要的目标文件app.jar的lib目录下。
在ant的build文件中定义lib所在目录的classpath:
<path id="queue-classpath">
<fileset dir="${queue.dir}" includes="**/*.jar" />
</path>
target定义:
<target name="queue-deploying" description="队列部署">
<unjar src="${svn.src.basedir}/lib/sfframe.jar" dest="${tmp.queue.dir}" />
<delete file="${tmp.queue.dir}/META-INF/MANIFEST.MF" />
<pathconvert property="mf.classpath" pathsep=" " description="把上面定义的path转换成property,path中jar包的路径用空格分开">
 <mapper>
    
 
<chainedmapper>
        <!-- 移除绝对路径 -->
        <flattenmapper />
        <!-- 加上lib前缀 -->
        <globmapper from="*" to="lib/*" />
       </chainedmapper>
     </mapper>
       <path refid="queue-classpath" description="path引用了上面定义的queue-classpath" />
    </pathconvert>
    <jar jarfile="${queue.dir}/sfframe.jar" basedir="${tmp.queue.dir}">
 
<!-- define MANIFEST.MF -->
 
<manifest>
 
<attribute name="Main-Class" value="com.ai.sfframe.common.RmiServer" />
  
<!--section name="common">
  
<attribute name="Specification-Title" value="${component.name}" />
 
<attribute name="Specification-Version" value="${component.version}" />
  
<attribute name="Specification-Vendor" value="${component.vendor}" />
    
 
<attribute name="Implementation-Title" value="${component.name}" />
      <attribute name="Implementation-Version" value="${component.version} ${TODAY}" />
      <attribute name="Implementation-Vendor" value="${component.vendor}" />
  
 
</section-->
    
 <!-- finally, use the magically generated libs path -->
  
 
 <attribute name="Class-Path" value="${mf.classpath}" />
    </manifest>
 </jar>
</target>

 

转载:

转载于:https://www.cnblogs.com/diyunpeng/archive/2011/09/03/2165888.html

你可能感兴趣的文章
HDU 1754 I hate it
查看>>
实现滑动出现删除按钮的代码
查看>>
windows提权exp列表
查看>>
一个老软件测试工程师的日志(转)
查看>>
结对编程
查看>>
Android studio来开发移动App--SQA计划和系统测试规程
查看>>
模式学习(一)
查看>>
高精度计算(二)
查看>>
二位几何运算类
查看>>
ZOJ 3622 Magic Number 打表找规律
查看>>
BZOJ 1079: [SCOI2008]着色方案 记忆化搜索
查看>>
cdoj 1136 邱老师玩游戏 树形背包
查看>>
BZOJ 2751: [HAOI2012]容易题(easy) 数学
查看>>
UVALive 6910 Cutting Tree 并查集
查看>>
World final 2017 题解
查看>>
平摊分析
查看>>
开发工具分享
查看>>
hadoop安装问题
查看>>
IOS initWithNibName 和 loadNibNamed的区别
查看>>
thinkphp 一些常用写法
查看>>