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

查看:20
本文介绍了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);

与此同时,客户端将指定(以某种方式???)具有要连接的 URL、超时等的属性文件详细信息.

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天全站免登陆