0

I am reading application.properties file using ResourceBundle class. I am getting the exception. below is my file location.

enter image description here

I am accessing it under static block and then rather reading these variable in class. But it is throwing exception.

package org.dynamicentity.shruti.util;
import java.util.ResourceBundle;
import javax.json.JsonObject;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class ConnectionUtil {
    
    public static String baseUrl,tokenUrl,grantType,scope,user,password,skillName, accessToken,filePath;
    
    static
    {
    
        ResourceBundle rb= ResourceBundle.getBundle("/ServletContext/WebContent/WEB-INF/lib/application.properties");
        skillName=rb.getString("chatbot.skillName");
        baseUrl= rb.getString("chatbot.baseUrl");
        tokenUrl= rb.getString("chatbot.tokenUrl");
}

it is throwing below exception.

Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.dynamicentity.practice.ReadDynamicEntityModular.main(ReadDynamicEntityModular.java:24)
Caused by: java.util.MissingResourceException: Can't find bundle for base name /ServletContext/WebContent/WEB-INF/lib/application.properties, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
    at java.util.ResourceBundle.getBundleImpl(Unknown Source)
    at java.util.ResourceBundle.getBundle(Unknown Source)
    at org.dynamicentity.util.ConnectionUtil.<clinit>(ConnectionUtil.java:25)
    ... 1 more

I put absolute path. also remove .proeprties from file name but still it is not working.

  • 1
    Btw, `java.util.ResourceBundle` is the wrong tool for the job. You don't have a i18n bundle file there but a simple configuration file. You're supposed to use `java.util.Properties` then. See also Oracle's own basic Java SE tutorials. – BalusC Aug 10 '20 at 21:39
  • Thank you @BalusC you helped me many times. I am basically a database developer, first time I got assignment in java and I am learning every bit. your help is really appreciated Balu. –  Aug 10 '20 at 22:17

0 Answers0