当前位置: 代码迷 >> Java相关 >> java程序打成jar包后,提示找不到资源文件解决方法
  详细解决方案

java程序打成jar包后,提示找不到资源文件解决方法

热度:6560   发布时间:2013-02-25 21:47:56.0
java程序打成jar包后,提示找不到资源文件
为方便更改配置文件,我把一个java project 打包(没有包括配置文件),jar文件和配置文件放在同一文件下,部署到linux下执行的时候提示:找不到资源配置文件,该怎么办???

以下是获取配置文件的部分代码:
 private static void initConfigInfo()
  {
  ResourceBundle messages = ResourceBundle.getBundle("monitor_config");
  Enumeration e = messages.getKeys();
  configInfo = new Hashtable();
  while (e.hasMoreElements()) {
  String key = (String)(String)e.nextElement();
  String value = messages.getString(key);
  configInfo.put(key, value);
  }

linux下运行的时候提示找不到mointor_config.properties;

------解决方案--------------------------------------------------------
没使用过这个类解析properties,我一直用的是
Java code
private static void load(){        try {            InputStream in = InitDBConfig.class.getResourceAsStream("/config_db.properties");            Properties p = new Properties();            p.load(in);            // 读取数据库配置            conn.setDriver(p.getProperty("db.driver"));            conn.setUrl(p.getProperty("db.url"));            conn.setUserName(p.getProperty("db.username"));            conn.setPassword(p.getProperty("db.password"));        } catch (IOException e) {            logger.error("数据库配置文件不存在!");            e.printStackTrace();        }    }
------解决方案--------------------------------------------------------
那你可能只有在固定这个配置文件的路径了。除了基本没办法
  相关解决方案