Java Manifest.mf classpath issues

荒凉一梦 提交于 2019-12-30 10:30:12

问题


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!


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/332522/java-manifest-mf-classpath-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!