JAR文件如何读取外部属性文件 [英] How a JAR file can read an external properties file

查看:146
本文介绍了JAR文件如何读取外部属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序的连接池组件(JAR文件)。截至目前,应用程序连接详细信息与JAR文件捆绑在一起(在 .properties 文件中)。

We have a connection pooling component (JAR file) for one of our application. As of now the application connection details are bundled with-in the JAR file (in .properties file).

我们可以让它更通用吗?我们可以让客户端告诉属性文件详细信息(路径和文件名)并使用JAR来获取连接吗?

Can we make it more generic? Can we have the client tell the properties file details (both the path and the file name) and use the JAR to get the connection?

有什么东西是有意义的吗?在客户端代码中像这样:

Does it make sense to have something like this in the client code:

XyzConnection con = connectionIF.getConnection(uname, pwd);

除此之外,客户端将指定(以某种方式???)属性文件详细信息要连接的网址,超时等等。

Along with this, the client will specify (somehow???) the properties file details that has the URLs to connect, timeout etc.

推荐答案

http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html

有多种方法,上面的文章提供了更多详细信息

multiple approaches are available, the article above provides more details

 ClassLoader.getResourceAsStream ("some/pkg/resource.properties");
 Class.getResourceAsStream ("/some/pkg/resource.properties");
 ResourceBundle.getBundle ("some.pkg.resource");

这篇关于JAR文件如何读取外部属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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