如何使用GlassFish的属性文件 [英] How to use a property-file with GlassFish

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

问题描述

我正在创建一个在GlassFish中运行的Web服务,我想要一些自定义属性。为此,我使用属性类。我使用的代码是:

I'm creating a web service, which run in GlassFish, and I want to have some custom properties. For this I'm using the Properties class. The code I'm using is:

Properties p=new Properties();
File f=new File(System.getProperty("user.dir"), "settings.properties");
p.load(new FileInputStream(f));  

但是如何获得 settings.properties -file在我的config目录中?

But how do I get the settings.properties-file in my config directory?

我不确定我的类路径,因为这是由NetBeans和GlassFish管理。我假设我的 .war - 文件添加到类路径时,部署...

I'm not sure about my classpath, since this is managed by NetBeans and GlassFish. I assume my .war-file is added to the classpath, when deploying...

我自己的解决方案,但如果任何人可以想出一个更好的解决方案,这将是非常受欢迎...

I've added my own solution, but if anyone could come up with a better solution, it would be highly welcome...

推荐答案

解决方案实际上很简单:

The solution that works is actually pretty simple:

URL url =  this.getClass().getResource("/package/name/file.properties");
p = new Properties();
p.load(new FileInputStream(new File(url.getFile())));

为什么没有人来这里?

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

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