Re: trivial third party jar dependancy
thufir wrote:
So, that's pretty cool, and now I know it's just a matter manifests
(yes?). When Foo.jar is created, the manifest must include a reference
to Calculations.jar as above so that I can:
java -jar Foo.jar
Yes! Good job. I just showed you the first part -- with a .class file,
the -classpath on the java command [1] points to the jar files, or other
classes or .zip files, that the .class uses.
With java -jar, you have to set the Class-Path property. For whatever
reason, java -jar ignores any classpath you specify on the command line.
This is very counter intuitive to me, but there it is.
To set it, I made a jar file of just your HellowWorldApp and set the
classpath.
Brenden@Homer ~/Dev/misc/thufirTest
$ jar umf build2/classpath.mf dist/hello.jar
Mar 27, 2008 8:20:46 PM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path.
Ensure that the manifest does not have duplicate entries, and
that blank lines separate individual sections in both your
manifest and in the META-INF/MANIFEST.MF entry in the jar file.
Brenden@Homer ~/Dev/misc/thufirTest
$ cat build2/classpath.mf
Class-Path: ./fibonacci.jar
Brenden@Homer ~/Dev/misc/thufirTest
$ java -jar dist/hello.jar
Hello World!
the fibonacci of 9 is: 34
But it helps if you wrestle around with this yourself, if you want to
remember it later.
BTW, you should be able to build on the command line without using so
many cd (change directories). And you can use relative paths, you don't
need the full path. But this is not a big deal, it should be seldom
that you need actually do it by hand. (I did this as an exercise for
myself to see if I remember it all. I only made a couple of mistakes. :D)