zoukankan      html  css  js  c++  java
  • ANT构建JAR包时设置MANIFEST.MF的ClassPath属性的技巧 规格严格

    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>

     

    转载:http://ribbonchen.blog.163.com/blog/static/1183165052011327113745129/

    http://quicker.iteye.com/blog/744953

    http://ant.apache.org/manual/Types/zipfileset.html

    http://www.ibm.com/developerworks/cn/java/j-5things6.html

  • 相关阅读:
    Android Studio Gradle 添加.so 支持文件
    poj 3270 更换使用
    linux通过使用mail发送电子邮件
    php 上传文件 $_FILES['']['type']的值
    浅谈Base64编码
    expect实现ssh自动登录
    C++ 多源码文件简单组织
    linux下修改hostid
    SQLite/嵌入式数据库
    类内数组声明,“类外”指定大小
  • 原文地址:https://www.cnblogs.com/diyunpeng/p/2165888.html
Copyright © 2011-2022 走看看