How do you replace the class of a Maven dependency?

前端 未结 3 1946
予麋鹿
予麋鹿 2021-01-05 06:56

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:

3条回答
  •  有刺的猬
    2021-01-05 07:29

    Here is a detailed guide describing what I did exactly:

    1. Create new Maven project in Eclipse
    2. Configure Maven settings of new project (Important: Use the same group and artifact ID and only change the version number)

      
          4.0.0
      
          com.sun.xml.wss
          xws-security
          3.0-java8-fix
      
          
              UTF-8
              1.8
          
      
      
    3. Add dependency of bugged JAR

      
          
              com.sun.xml.wss
              xws-security
              3.0
              
                  
                    xmldsig
                    javax.xml.crypto
                  
                  
                    activation
                    javax.activation
                  
              
          
         
      
    4. Create Java file in the same package of class that needs to be fixed

      package com.sun.xml.wss.impl.apachecrypto;
      
      public class EncryptionProcessor {
          // The FIX goes here
      }
      
    5. Add Maven shade build plug in to handle creation of patched JAR file (this is not the only plug in to handle this kind of task - e.g. dependency:unpack)

      
          
              
              
                  org.apache.maven.plugins
                  maven-shade-plugin
                  2.1
                  
                      
                          package
                          
                              shade
                          
                          
                              
                                  
                                      com.sun.xml.wss:xws-security:3.0
                                      
                                          **/*.class
                                          **/*.xml
                                      
                                      
                                          
                                  com/sun/xml/wss/impl/apachecrypto/EncryptionProcessor.class
                                          
                                      
                                  
                              
                          
                      
                  
              
          
      
      
    6. Include patched JAR in other projects as necessary (Note: If you experience ClassNotFoundExceptions or similar errors do this: Right-click on the project -> Properties -> Maven -> "Resolve dependencies from Workspace projects":false)

    In case you are not familiar with Maven. Here is the complete pom.xml: http://pastebucket.com/88444

提交回复
热议问题