IntelliJ IDEA java maven项目读取配置文件信息 java.util.ResourceBundle 方式
一、在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 + " ---------- ");
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步