Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何访问Wicket中的中央ResourceBundle_Java_Properties_Resources_Wicket_Resourcebundle - Fatal编程技术网

Java 如何访问Wicket中的中央ResourceBundle

Java 如何访问Wicket中的中央ResourceBundle,java,properties,resources,wicket,resourcebundle,Java,Properties,Resources,Wicket,Resourcebundle,Wicket的国际化是通过在同一文件夹中的许多小属性文件实现的,比如html文件 我的Architecture是webapp文件夹中的一个属性文件或其他唯一文件夹 我最喜欢的例子是: src/java/main/net/kog/wicketapplication.java: getResourceSettings().getResourceFinders().add( new WebApplicationPath(getServletContext(), "resource"));

Wicket的国际化是通过在同一文件夹中的许多小属性文件实现的,比如html文件

我的Architecture是webapp文件夹中的一个属性文件或其他唯一文件夹

我最喜欢的例子是: src/java/main/net/kog/wicketapplication.java:

getResourceSettings().getResourceFinders().add(
       new WebApplicationPath(getServletContext(), "resource"));
BundleStringResourceLoader bundle = new BundleStringResourceLoader("text.properties");
getResourceSettings().getStringResourceLoaders().add(bundle);
// Test
String str = bundle.loadStringResource(net.kog.resource.Text.class, "login.noscript", Locale.getDefault(), null, null);
System.out.println(str);
标记:

<div wicket:id="login.noscript" id="js"/>

但无论我在哪里找到ResourceBundle的text.properties文件,都没有返回任何字符串。 试用地点:

  • src/main/webapp
  • src/main/webapp/resource
  • src/main/webapp/WEB-INF/resource
  • src/main/webapp/WEB-INF/classes/resource
  • src/main/resources
  • src/main/resources/resource
  • src/main/resources/net/kog/resource
有关如何拆分或组合应用程序中的资源束的详细信息,请阅读。

解决方案:
  • 首先,martin-g的回答给出了正确的方向。属性文件必须与应用程序类同名(“WicketApplication.properties”)
  • 其次,将Wicket(src\main\resources\log4j2.xml)中的debuglevel从LEVEL.INFO更改为LEVEL.DEBUG非常有用。Wicket试图加载的URL(路径)有很多信息
  • 第三,我缩短了访问属性文件的时间,因为我删除了net.kog.WicketApplication.init()中的IsropertiesFilePropertiesLoader(ISO-8859格式化属性文件)和XmlFilePropertiesLoader。代码:

    列表属性加载器=
    ((PropertiesFactory)getResourceSettings().getPropertiesFactory()).getPropertiesLoaders();
    getResourceSettings().getPropertiesFactory().clearCache();
    propertiesLoader.clear();
    添加(新的UtfPropertiesFilePropertiesLoader(“属性”,“utf-8”);
    

  • 我的UTF-8属性文件的完整路径是src/main/webapp/net/kog/WicketApplication.properties

    这方面我已经反复阅读了上周的内容,我尝试了一些想法,但我发现没有找到正确的信息。你指的是哪一个子点?将你的i18n内容放在src/main/resources/net/kog/wicketapplication.properties中。确保它被复制到wicketapplication.class文件旁边的final.jar/.war文件中。然后使用组件#getSttring(someKey)、ResourceModel、application.getREsourceSettings().getLocalizer().getString(…)等。
    List<IPropertiesLoader> propertiesLoader = 
            ((PropertiesFactory)getResourceSettings().getPropertiesFactory()).getPropertiesLoaders();
    getResourceSettings().getPropertiesFactory().clearCache();
    propertiesLoader.clear();
    propertiesLoader.add(new UtfPropertiesFilePropertiesLoader("properties", "utf-8"));