3

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!

  • I assume this JAR contains your database driver; it's fairly common for an application to create its own java.net.URLClassLoader to pick up driver classes in a class specified through some application configuration. – erickson Dec 02 '08 at 04:58
  • Why don't just append the jar to the starting script of the app. Most app servers have an special part where to put these additional jars. – OscarRyz Dec 03 '08 at 19:11

2 Answers2

12

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
  • 265,237
  • 58
  • 395
  • 493
  • 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! –  Dec 02 '08 at 00:22
  • Nick: If you can, try using symbolic links. Thnks to erickson, though. Works fine, although I usually use three slashes (file:///opt/sybase) since otherwise the "host" part is missing and some tools need it. – Danny Milosavljevic Feb 13 '12 at 13:06
  • "To make your absolute paths work" -- Does that still work with Java 8? I can't get absolute paths to work, with or without "file://" prefix. – Itai Aug 16 '16 at 08:29
  • @sillyfly Use one or three slashes. Two slashes is not valid. – erickson Aug 18 '16 at 16:29
  • I've tried `file:///opt/...` or `/opt/...`, neither worked. I meant `file://` as a prefix to the complete absolute path, so 3 slashes in total. – Itai Aug 18 '16 at 16:45
  • @sillyfly Hmm. It's working for me as expected, on Mint with a slightly older Java 8 build: 1.8.0_66-b17. Any inability to read the jar (missing, not permitted) will result in the same stack trace. Have you created a simple test case and made it work under Java 7 and fail under Java 8? – erickson Aug 18 '16 at 17:36
0

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

Community
  • 1
  • 1
OscarRyz
  • 196,001
  • 113
  • 385
  • 569