简体   繁体   English

Java Manifest.mf类路径问题

[英]Java Manifest.mf classpath issues

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. 我一直在尝试运行一个jar文件-我们称它为test.jar-在Unix系统上使用Sybase jconn3.jar。

I have created a MANIFEST.MF file that has the following: 我创建了一个具有以下内容的MANIFEST.MF文件:

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

This gives a ClassNotFoundError. 这给出了ClassNotFoundError。 $SYBASE is the system variable that points to /opt/sybase13; $ SYBASE是指向/ 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: 但是,如果我将jconn3.jar文件从$ SYBASE / jConnect-6_0 / classes复制到与test.jar相同的目录,然后将MANIFEST.MF更新如下:

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; 现在,我已经能够通过在本地复制jconn3.jar文件来验证它是否有效。 my MANIFEST.MF file includes the path to my Main-Class, so that's not at issue here. 我的MANIFEST.MF文件包含我的Main-Class的路径,因此这里没有问题。

What do you think could be the problem? 您认为可能是什么问题? I've been looking at this thing for too long now. 我看这东西已经太久了。 Thanks! 谢谢!

The entries in the class-path are either relative to the JAR in which they are embedded (which you have working) or are URLs. class-path中的条目是相对于嵌入它们的JAR(您正在使用的)还是URL。 To make your absolute paths work, you'll need to convert them to URLs, eg, 为了使您的绝对路径有效,您需要将其转换为网址,例如,

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. 尽管JAR规范没有明确说明,但绝对file:方案URL确实在class-path属性中起作用。

Environment variables are not readed by the classloader AFAIK. 类加载器AFAIK不会读取环境变量。 However you could add the jar in a configuration script 但是,您可以在配置脚本中添加jar

Accoding to the specification the entries are relatives to the jar not absolute: 根据规范,条目是相对于jar的亲戚,而不是绝对的:

Class-Path : 类路径:

The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs. 此属性的值指定此应用程序或扩展程序所需的扩展程序或库的相对URL。 URLs are separated by one or more spaces. URL由一个或多个空格分隔。 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 http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html #Manifest规范

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM