java.util.MissingResourceException:找不到基本名称config,locale en的包

时间:2012-08-13 10:32:41

标签: java configuration-files jdeveloper resourcebundle

我看了这个问题的答案,但它们对我不起作用。 我在Resources文件夹中有一个名为“config_en.properties”的文件。 (项目 - >资源 - > config_en.properties)

jms_Address=t3://127.0.0.1:7101
connection_Lookup_Address=BatchApp-BatchGebelikTakip-BatchGebelikTakipEJB#tr.com.surat.esaglik.batch.ejb.IBatchGebelikTakipEJB

在我的java类中,我尝试阅读这个配置:

private static final String fileName="config"; 

public static final String jms_Address="jms_Address";
public static final String conn_Lookup_Address="connection_Lookup_Address";
private static ResourceBundle res;
private static ClassLoader cl;
static {
    try {
        cl = Thread.currentThread().getContextClassLoader();
        res = ResourceBundle.getBundle(fileName, Locale.ENGLISH, cl);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public void test(){
    System.out.println(res.getString(jms_Address).
}

但我收到此错误消息:

java.util.MissingResourceException: Can't find bundle for base name config, locale en
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:952)
    at tr.com.surat.esaglik.batch.Main.<clinit>(Main.java:34)
java.lang.NullPointerException
    at tr.com.surat.esaglik.batch.Main.getInitialContext(Main.java:74)
    at tr.com.surat.esaglik.batch.Main.run(Main.java:43)

有什么问题?

enter image description here

1 个答案:

答案 0 :(得分:3)

我制作了一个简单的应用程序,展示了如何加载资源包

enter image description here

Main.java

package org.stackoverflow.main;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * @author Eugene Pavlovsky
 * @since 13.08.12
 */
public class Main {

  public static void main(String[] args) {
    ResourceBundle resourceBundle = ResourceBundle.getBundle("org.stackoverflow.config.config", Locale.ENGLISH);
    System.out.println(resourceBundle != null);
  }
}