2005/08/18

Java Jar file manifests, and Class-Path

I've been having trouble building jar files. I'm using Apache ant on Mac OS X. I have been unable to create valid Class-Path values when using ant to generate my MANIFEST.MF files.

The solution: compose my MANIFEST.MF file manually (based on the broken MANIFEST.MF created by ant). It turns out that Class-Path can be specified as a series of space-separated paths extending across multiple lines, with leading indentation. F'rinstance:


Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.4
Created-By: 1.4.2-50 ("Apple Computer, Inc.")
Main-Class: JChemLoader
Class-Path: /usr/local/jchem/lib/batik-core.jar
/usr/local/jchem/lib/chart.jar /usr/local/jchem/lib/dom4j.jar
/usr/local/jchem/lib/jchem.jar
/usr/local/lib/java/postgresql.jdbc.jar


As long as no single Class-Path entry is more than 70-71 characters in length, this should work.

The problem with ant-generated Class-Path values was that the values, when written out, were being split at arbitrary points. (The value I was supplying to ant was a colon-separated sequence of pathnames. Maybe that was part of my problem?) ant was trying to satisfy the rules for jar file formatting, as specified by Sun:


Line length:

No line may be longer than 72 bytes (not characters), in its UTF8-encoded form. If a value would make the initial line longer than this, it should be continued on extra lines (each starting with a single SPACE).


Perhaps it's just my lack of familiarity, but I find Java, jar files, and CLASSPATH to be a vile combination. Python (PYTHONPATH) handles things much more cleanly. Even gcc and make handle library locations in a much more pleasant way.

No comments: