How do you replace the Maven dependency class?

There is a maven dependent class that is not compatible with Java 8.

How to fix this problem?

Now I am doing the following:

  • Create a package with the same name
  • Create a class with the same name in this package
  • Copy and paste the code
  • Fix incompatible API call

The problem is that this class contains API calls for restricted classes, and although I changed the Eclipse compiler settings (Window -> Preferences -> Java -> Compiler -> Error / Warnings -> Deprecated and restricted APIs -> Forbidden link (access rule): Error -> Warning) To allow access to the project, it will be compiled only occasionally. If it does not compile, I will get the error "cannot find character".

Edit:

Here are the details you asked:

Edit-2:

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/EncryptionProcessor.java:[1482,98] cannot find symbol 
+4
source share
3 answers

Common decision:

  • download all project sources
  • apply your modification
    • Use version control so that changes are not lost.
  • change version in pom.xml , e.g. from 3.0 to 3.0-patched
  • launch maven build
  • copy created artifacts to / Artifactory repository if you use one
  • change the dependency version in your own project
+2
source

Here is a detailed guide describing what I did exactly:

  • Create a New Maven Project in Eclipse
  • Configure the Maven settings for the new project (important: use the same group and artifact identifiers and just change the version number)

     <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sun.xml.wss</groupId> <artifactId>xws-security</artifactId> <version>3.0-java8-fix</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> </project> 
  • Add Listened JAR Dependency

     <dependencies> <dependency> <groupId>com.sun.xml.wss</groupId> <artifactId>xws-security</artifactId> <version>3.0</version> <exclusions> <exclusion> <artifactId>xmldsig</artifactId> <groupId>javax.xml.crypto</groupId> </exclusion> <exclusion> <artifactId>activation</artifactId> <groupId>javax.activation</groupId> </exclusion> </exclusions> </dependency> </dependencies> 
  • Create the Java file in the same class package that you want to fix

     package com.sun.xml.wss.impl.apachecrypto; public class EncryptionProcessor { // The FIX goes here } 
  • Add a built-in Maven plugin for processing the created fixed JAR file (this is not the only plug-in for handling such tasks - for example, the dependency: unpacking)

     <build> <plugins> <!-- plug in for creation of patched JAR file --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <filters> <filter> <artifact>com.sun.xml.wss:xws-security:3.0</artifact> <includes> <include>**/*.class</include> <include>**/*.xml</include> </includes> <excludes> <exlude> com/sun/xml/wss/impl/apachecrypto/EncryptionProcessor.class </exlude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin> </plugins> </build> 
  • Include the fixed JAR in other projects as needed (Note. If you experience ClassNotFoundExceptions or similar errors, do the following: Right-click the project → Properties → Maven → “Allow dependencies from Workspace projects”: false)

If you are not familiar with Maven. Here is the full pom.xml: http://pastebucket.com/88444

+4
source

Like Stephen S., answer, but using the maven-dependency-plugin . Based on this blog post .

I changed the name of the corrected library (not the version), but it depends on your needs, which is better for you.

The dependency on the source library should be marked as <optional>true</optional> . Otherwise, projects depending on your patched library will also depend on the source library, which means that both the patched and the original version will be in the class path, which can lead to all problems.

If your project is a child project, you can still use a completely different version of groupId and version than your parent pom. Never mind.

You can exclude classes that you fix from unpacking, but this is probably not necessary because Maven will first unzip the source library and then compile your new version, which means that the original classes are overwritten. Nice!

 <?xml version="1.0"?> <project xmlns="http://maven.apache.org/POM/4.0.0"> <modelVersion>4.0.0</modelVersion> <!-- remove this if you don't have a parent pom --> <parent> <groupId>my.company</groupId> <artifactId>my.company</artifactId> <version>1.2.3</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>com.foo</groupId> <artifactId>foo-bar-patched</artifactId> <version>4.5.6</version> <build> <plugins> <plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <goals> <goal>unpack</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>com.foo</groupId> <artifactId>foo-bar</artifactId> <outputDirectory>${project.build.directory}/classes</outputDirectory> <!-- excludes are probably not necessary --> <!-- <excludes>**/Foo.class,**/Bar.class</excludes> --> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.foo</groupId> <artifactId>foo-bar</artifactId> <version>4.5.6</version> <optional>true</optional> </dependency> </dependencies> </project> 
0
source

All Articles