创建pathing jar

pathing jar是一个特殊的jar:

  • 该jar文件只包含manifest.mf文件
  • 该manifest文件只包含Class-Path,列出了所有需要真正加到classpath中的jar,或者directory

需要pathing jar的原因是windows下command line额长度限制(8k),无论你怎么声明你的classpath:

  • set CLASS_PATH=allpaths
  • set CLASS_PATH=path1; set CLASS_PATH=%CLASS_PATH%;path2
  • java -cp allpaths

结果都会是:

The input line is too long.
The syntax of the command is incorrect.

 

对于ant,解决方案是:http://stackoverflow.com/questions/201816/how-to-set-a-long-java-classpath-in-msdos-windows

<macrodef name="create-pathing-jar">
    <sequential>
      <ivy:cachepath pathid="all_classpath" conf="runtime" type="jar"/>
      <pathconvert property="converted_all_classpath" refid="all_classpath" pathsep=" " dirsep="/">
        <map from="/" to="file:////"/>;
      </pathconvert>
      <jar jarfile="pathing.jar" filesetmanifest="merge">
        <manifest>
          <attribute name="Class-Path" value="${converted_all_classpath}"/>
        </manifest>
      </jar>
    </sequential>
  </macrodef>

一般需要做个pathcovert,加上一个file:///的前缀: http://en.wikipedia.org/wiki/File_URI_scheme

 

对于gradle,解决方案是:http://stackoverflow.com/questions/5434482/how-can-i-create-a-pathing-jar-in-gradle

 

posted @ 2013-08-24 16:51 lzprgmr 阅读(...) 评论(...) 编辑 收藏

黄将军