Java war包取之外的properties文件

由于服务器发布war项目不尽相同,所以获取properties也不尽相同。

tomcat:

Properties config = new Properties();
String url = Thread.currentThread().getContextClassLoader().getResource("").getPath().replaceAll("%20", " ");
String path = url.substring(0, url.indexOf(APPLICATION_NAME)) + PROPERTIES_FILE_NAME;
config.load(new FileInputStream(path));

glassfish:

question:

I'm currently migrating from WebSphere 6.1 to Glassfish v3, I managed to deploy an application but I'm stuck trying to locate where to put the properties files and getting the application find them.
On WebSphere 6.1 was something like "/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/properties"
Where would that be for GlassFish v3? "/opt/oracle/glassfishv3/glassfish/domains/domain1/.......?"

answer:

you could put the properties file into the lib/classes directory of your domain. Everything in that directory gets added to the classpath.

posted @ 2013-04-12 14:29  VoctrALs  阅读(422)  评论(0编辑  收藏  举报