How do you replace the class of a Maven dependency?

There is a class in a maven dependency that is incompatible with Java 8.

How do you properly fix that problem?

Right now I'm doing the following:

  1. Create a package with the same name
  2. Create a class with the same name in that package
  3. Copy and paste the code
  4. Fix the incompatible API call

The problem is that this class contains API calls to restricted classes and although I changed the Eclipse compiler settings (Window -> Preferences -> Java -> Compiler -> Error/Warnings -> Deprecated and restricted API -> Forbidden reference (access rule): Error -> Warning) to allow access the project will only compile sometimes. If it doesn't compile I'll get a "can't find symbol" error.


Here are the details you asked for:


Maven build error:

 [ERROR] symbol:   class XMLCipher
 [ERROR] location: class com.sun.xml.wss.impl.apachecrypto.EncryptionProcessor
 [ERROR] /C:/Users/{name}/development/eclipse_workspace/git/xws-security/src/main/java/com/sun/xml/wss/impl/apachecrypto/[1482,98] cannot find symbol


  • General solution:

    • download all project sources
    • apply your modification
      • use version control so that change isn't lost
    • change version in pom.xml, for example from 3.0 to 3.0-patched
    • launch maven build
    • copy generated artifacts to you repository/Artifactory, if you use one
    • change dependency version in your own project