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