简体   繁体   English

将 Java Resource Bundle 放在项目环境中的什么位置

[英]Where to put Java Resource Bundle in Project Environment

I am trying to use resource bundle in my project.我正在尝试在我的项目中使用资源包。 i am new for development.我是开发新手。 is it professional way to put property files inside src/ folder i mean inside jar.将属性文件放在src/文件夹中是专业的方式src/我的意思是在 jar 中。

Also i have tried by placing my propert [AppProp] outside of the src folder [/resources/properties/AppProp] .我也尝试将我的[/resources/properties/AppProp] [AppProp]放在src文件夹[/resources/properties/AppProp] I have added Add Class Folder from build path eclipse.我已经从构建路径 eclipse 添加了添加类文件夹 I am trying to run this in eclipse.我正在尝试在 eclipse 中运行它。 But it says Can't find bundle for base name.但它说找不到基本名称的包。 Please see my below code.请看我下面的代码。 Please provide any suggestion.请提供任何建议。

public class PropertyReader {

    private String bundleName = null;

    ResourceBundle resourceBundle = null;

    public PropertyReader(String bundle){
        this.bundleName = bundle;
        loadProperty();
    }

    public void loadProperty(){
        try{
            resourceBundle = ResourceBundle.getBundle(bundleName);
        } catch(Exception e){
           e.printStackTrace();
        }
    }

    public static void main(String a[]){
        try{
            PropertyReader pr = new PropertyReader("resources/properties/AppProp");
        } catch(Exception e){
            e.printStackTrace();
        }
    }

}

You don't need to change the code.您无需更改代码。 But make sure following但请确保遵循

1) You are providing the correct file path. 1) 您提供了正确的文件路径。

2) File type must be .properties in your case it should be be like AppProp.properties 2)文件类型必须是.properties在你的情况下它应该像AppProp.properties

There are lot of techniques/standards to organize your source files and code.有很多技术/标准来组织您的源文件和代码。

But for now above points are the solution of your problem.但现在以上几点是您问题的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM