在jbx中将java程序和配置文件中打包成jar后发布,然后在其他程序调用的它的时候报读取配置文件错误。如下:
      
      2009-2-3 17:04:06 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from file [E:\evaljar\com_maqi\classes\postexp\config\applicationContext.xml]
postexp.IllegalExpressionException: Exception occurs on parsing: IOException parsing XML document from file [E:\evaljar\com_maqi\classes\postexp\config\applicationContext.xml]; nested exception is java.io.FileNotFoundException: E:\evaljar\com_maqi\classes\postexp\config\applicationContext.xml (系统找不到指定的路径。)
at postexp.defaultimpl.SimpleParser.parse(SimpleParser.java:133)
at postexp.defaultimpl.EvalApi.getResult(EvalApi.java:22)
at com.maqi.eval.Untitled1.main(Untitled1.java:10)       读取配置文件的程序如下:
      
           String absolutePath = this.getClass().getResource("/").getPath().replaceAll("/","\\\\");
          File s= new File(absolutePath+"postexp//config//applicationContext.xml");
    哪位大侠帮忙解决一下

解决方案 »

  1.   

    配置文件用ResourceBundle rsb=ResourceBundle.getBundle("XXX");
      

  2.   


    //你试试这样的方法
    String absolutePath = this.getClass().getResource("/").getFile();
      

  3.   

    private static String CONFIG_FILE = "dbconfig"; public static Connection getConnection() {
        Connection conn = null;
        // load the database connect infornmatin  from file
    ResourceBundle bundle = ResourceBundle.getBundle(CONFIG_FILE);
    String jdbcClassName = bundle.getString("jdbc.driverClassName");
    String url = bundle.getString("jdbc.url");
    String username = bundle.getString("jdbc.username");
    String password = bundle.getString("jdbc.password");
    try {
                                 .........配置文件dbconfig.properties