For updating in my .properties
file I am using Apache Commons Configuration's PropertiesConfiguration. But as I am using the code as :
try {
PropertiesConfiguration properties = new PropertiesConfiguration("dao.properties");
} catch (ConfigurationException ex) {
}
I am getting this error:
incompatible types
required: java.lang.Throwable
found: org.apache.commons.configuration.ConfigurationException
What is going wrong here?
I am using it first for the first time.
P.S.: Is there any comparatively equivalent or better library available for handling .properties
?
You are using incompatible versions of the library. Try:
- commons-configuration-1.7
- commons-collections-3.2.1
- commons-lang-2.6
- commons-logging-1.1.1
It works for me.
I had the same problem and this post saved my day; wanted to share a bit more that I learned in the process:
Try just adding the commons-lang library before you add all four mentioned by Sergio. My code looks remarkably similar the example referenced in the question and I found those two libraries satisfied the dependencies needed.
@Haroldo - you're correct in the library mismatch. Tried commons-lang 3.3 first with no success. Verified that commons-configuration-1.9 and commons-lang-2.6 play well together.
@Asif - is there a particular reason that you need the added functionality of the Apache library? I've found that the java.util.Properties class works just fine for most of my applications, and doesn't require the additional libraries. Of course, that depends on what you are doing with the values returned.
Your reference to "dao.properties" suggests to me that you are deploying your code in a web service environment. In that case, you need to ensure that the libraries the web service loads and the libraries you are referencing are exactly the same (at least the same version), as differences can cause errors like the one you encountered -- the class loaded by the webservice classloader is different than the one loaded by your app's classloader, hence the exception.