views:

4186

answers:

2

Hi all -

I've been trying to run a jar file - let's call it test.jar - that uses the Sybase jconn3.jar on a Unix system.

I have created a MANIFEST.MF file that has the following:

Class-Path: $SYBASE/jConnect-6_0/classes/jconn3.jar commons-net-1.3.0.jar

This gives a ClassNotFoundError. $SYBASE is the system variable that points to /opt/sybase13; I've also tried the following:

Class-Path: /opt/sybase13/jConnect-6_0/classes/jconn3.jar commons-net-1.3.0.jar

and

Class-Path: opt/sybase13/jConnect-6_0/classes/jconn3.jar commons-net-1.3.0.jar

However, if I copy the jconn3.jar file from the $SYBASE/jConnect-6_0/classes to the same directory as test.jar, and update my MANIFEST.MF to read as follows:

Class-Path: jconn3.jar commons-net-1.3.0.jar

The application runs as expected.

Now, I've been able to verify the jconn3.jar file works by copying it locally; my MANIFEST.MF file includes the path to my Main-Class, so that's not at issue here.

What do you think could be the problem? I've been looking at this thing for too long now. Thanks!

+3  A: 

The entries in the class-path are either relative to the JAR in which they are embedded (which you have working) or are URLs. To make your absolute paths work, you'll need to convert them to URLs, e.g.,

file:/opt/sybase13/...

There's no mechanism for using variables.

Although the JAR specification doesn't say it clearly, absolute file: scheme URLs do work in the class-path attribute.

erickson
This seems to be working for the time being. I wish there was a more flexible solution available with the default Manifest file (since the Prod server has a different path for this file than the Dev server), but it will get this up and running for now. Thanks!
A: 

Environment variables are not readed by the classloader AFAIK. However you could add the jar in a configuration script

Accoding to the specification the entries are relatives to the jar not absolute:

Class-Path :

The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs. URLs are separated by one or more spaces. The application or extension class loader uses the value of this attribute to construct its internal search path.

http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html #Manifest Specification

OscarRyz