Java Manifest.mf classpath issues

17,113

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.

Share:
17,113
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    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!

  • Admin
    Admin over 15 years
    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!
  • Danny Milosavljevic
    Danny Milosavljevic about 12 years
    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.
  • Itai
    Itai over 7 years
    "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.
  • brady
    brady over 7 years
    @sillyfly Use one or three slashes. Two slashes is not valid.
  • Itai
    Itai over 7 years
    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.
  • brady
    brady over 7 years
    @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?