2

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 ?

Asif
  • 4,980
  • 8
  • 38
  • 53

3 Answers3

4

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.

  • Means I have to include `collections`, `lang`, and `logging` libraries together with `configuration-1.7`? – Asif Mar 29 '12 at 15:35
  • @Asif yes, see the [Runtime Dependencies](http://commons.apache.org/configuration/dependencies.html) –  Mar 29 '12 at 15:40
  • A small warning to whoever happens to stumble into that same problem: don't try using commons-lang 3.x; it's not compatible with commons-configuration 1.x. – Haroldo_OK Feb 05 '13 at 11:21
  • A key here is to note that you need `commons-lang-2.6` NOT `commons-lang-3.1`. – wmarbut Jun 28 '13 at 16:18
  • Hello!, I hope some people still viewing this issue because I am now experiencing it. It works on my local machine, specified everything in my pom.xml and no issues. I then decided to run this application in an updated version of my intelliJ IDE on a VM, and I am now seeing this error, it works locally but not on the VM, I have tried the latest libraries and it does not seem to resolve my issue, can anyone provide me with a solution or care to explain why this occurs? – Riidonesh Feb 08 '21 at 10:29
1

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.

heyhey2k
  • 66
  • 1
  • 5
0

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.

Attila
  • 28,265
  • 3
  • 46
  • 55