将文件加载到分发罐外部 [英] Load files External To The Distribution Jar

查看:70
本文介绍了将文件加载到分发罐外部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个Java程序,该程序可以从JAR文件打包并运行。我需要一些用户可更改的配置文件,这些文件只是以下文本行:

I have written a Java program which I package and run from a JAR file. I need to have some user-changeable configuration files which are simply text lines of:

key = value

key = value

格式。要加载这些文件,我使用了这里。当我通过Netbeans IDE运行程序时,一切正常,因为我已经在Project属性中包括了用于存储配置文件的目录。

format. To load these files I used the class described here. When I run my program through Netbeans IDE all works fine as I have included the directory where I store the configuration files in the Project properties.

问题是在构建自己的目录时出现的应用程序转换成JAR文件。因为我希望配置文件是用户可编辑的,所以我将它们保留在JAR之外,但位于同一目录中,但是现在当我从命令行运行应用程序时,它找不到配置文件。如果我手动将文件添加到ROOT文件夹中的JAR文件中,那么一切都很好。

The problem comes when I build my application into a JAR file. As I want the configuration files to be user-editable I keep them OUTSIDE of the JAR but in the same directory but now when I run my application from the command line it cannot find the configuration files. If I manually add the files to JAR file at the ROOT folder then all is well.

那么如何告诉Java在JAR之外查找我的可加载文件? -classpath选项无效。

So how can I tell Java to look outside of the JAR for my loadable files? The -classpath option has no effect.

推荐答案

我通过引用问题。我将当前目录添加到jar的清单文件中,并且可以正常工作。

I resolved it by referring to this question. I Added the current directory to the MANIFEST file of the jar and it works.

在这种情况下,为什么-classpath选项被忽略了?安全吗?

Why is the -classpath option ignored in this case I wonder? Security?

这篇关于将文件加载到分发罐外部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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