指定jar的类路径 [英] Specifying classpath for a jar

查看:110
本文介绍了指定jar的类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置JAR的类路径,以便我的ResourceBundle可以从中获取属性文件。

I am trying to configure the classpath of a JAR so that my ResourceBundle can pick up property files from it.

如果我从.class文件中运行它指定 -cp 标志它工作正常, System.err.println(System.getProperty(java.class.path)); 将打印 -cp 标志中指定的路径。

If I run it from the .class files and specify the -cp flag it works fine, and System.err.println(System.getProperty("java.class.path")); will print the path specified in the -cp flag.

如果我尝试创建一个jar文件, System.err.println(System.getProperty(java.class.path)); 总是打印jar文件的路径,并且属性文件没有被提取。

If I try and create a jar file for it, System.err.println(System.getProperty("java.class.path")); always prints the path of the jar file, and the property files aren't picked up.

看来如果你将它作为jar文件运行,你不能指定 -cp flag(这是我所希望的,因为切换正在使用的属性文件是很常见的)。我已经尝试在jar清单中指定它,但它仍然不起作用。

It seems if you are running it as a jar file you can't specify the -cp flag (which was what I was hoping, as it's common to switch which property files are being used). I've tried specifying it in the jar manifest instead, but it's still not working.

这是来自测试jar的代码和清单似乎不起作用:

Here is the code and manifest from a test jar that doesn't seem to work:

public final class Test {
    public static void main(final String[] args) {
        System.err.println(System.getProperty("java.class.path"));
    }
}

 

Manifest-Version: 1.0
Created-By: 1.6.0_20 (Sun Microsystems Inc.)
Main-Class: Test
Class-Path: /home/ajanuary/Projects/test/

edit
原始路径没有意义,所以我改变了它。我想指向一个ResourceBundle可以找到属性文件的目录。

edit The original path was rather meaningless so I changed it. I want to point to a directory which the ResourceBundle can find the property files in.

推荐答案

问题是我也有一个索引文件。如果您有索引文件,则将忽略Class-Path。

The problem was that I also had an index file. If you have an index file, the Class-Path will be ignored.

这篇关于指定jar的类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆