一些路径问题:
一、Jboss conf 目录下的路径
Properties props = System.getProperties();
String filePathUrl = props.getProperty("jboss.server.config.url");
// filePathUrl = file:/D:/Infor/wm/jboss-4.2.3.GA/server/wmprd-wmapp1/conf/
String filePath = filePathUrl.substring(filePathUrl.indexOf("/")+1)+"wmsconfig.properties";
// filePath = D:/Infor/wm/jboss-4.2.3.GA/server/wmprd-wmapp1/conf/wmsconfig.properties
Properties JMS_PROP = new Properties();
JMS_PROP.load(new FileInputStream(filePath));
String tcp = String.valueOf(JMS_PROP.get("jms.tcp"));
二、类路径 classpath
1. String path = Thread.currentThread().getContextClassLoader().getResource("").getPath()+"wmsconfig.properties";
2. String path = 类名.class.getClassLoader().getResource("").getPath()+ "wmsconfig.properties";
path = "/D:/Infor/wm/jboss-4.2.3.GA/server/default/deploy/wms.war/WEB-INF/classes/wmsconfig.properties"
System.getProperty("user.dir") // D:/Program Files/apache-tomcat-6.0.20/bin
本文介绍了在JBoss环境中两种不同的路径获取方式:一是通过系统属性获取JBoss配置目录下的文件路径;二是通过类加载器获取类路径下的配置文件。文中详细展示了如何利用Java的系统属性和类加载器来定位特定的配置文件。
1万+

被折叠的 条评论
为什么被折叠?



