一、在main目录下 新建 resources 目录 并将其设为 资源文件目录
创建config.properties文件
二、在pom.xml 中添加 下面代码 只这样 打包后 jar 才能有配置文件
<resources> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> <includes> <include>**/**.properties</include> <include>**/**.xml</include> </includes> <!-- <targetPath>/resources</targetPath> --> </resource> </resources>
三、具体实现的代码
import java.util.ResourceBundle
//读取参数 ResourceBundle resource = ResourceBundle.getBundle("config"); String strPbxIp = resource.getString("pbxIp");// String strPbxPort = resource.getString("pbxPort"); String strApiPwd = resource.getString("apiPwd"); //System.out.println( "pbx "+strPbxIp+" " + strPbxPort +" "+ strApiPwd +"---------- "); logger.info("pbx 参数: " + strPbxIp + " " + strPbxPort + " " + strApiPwd + " ---------- ");
标签:strPbxPort,resource,getString,配置文件,util,ResourceBundle,java From: https://www.cnblogs.com/hailexuexi/p/18279606