• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getContextClassLoader() problem

 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi every body I have one confution :

I have seen code like this :



Here actually geting the my.properties file by ClassLoader , instead of this could we take the my.properties file by
Class.forName("my.properties") or by using Resource Bundle ??

Which one is good and why ?

Thanks and regards,
S
 
cow clarke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just wonder can "Class.forName("my.properties")" works well?
Class.forName is used to load Class dynamically, isn't it?
Do you mean that "properties" is just a java class definition?
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replly.
The property is a property file with lot of key / value pair.

rgards,
S
 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will not work
You must try
Class.forName("my.package.myclass").getResourceAsStream("my.properties");

Or directly use ClassLoader

But the just delegates to

ResourceBundle generaly used for Locale specific properties and you will have to follow some conventions in naming the files.

In you case it is not advisable to use ResourceBundle because you are just loading a property file.

I would say you stick to your current code.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply ,
could you please explain what is properties as java class defination ?

regards,
S
 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Property as you already told
The property is a property file with lot of key / value pair.
is text file.
With Class#forName you are trying to load a class using its name. This method can not load text files .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic