Ste*_* S. 5 java eclipse dependencies maven
Maven依赖项中有一个与Java 8不兼容的类。
您如何正确解决该问题?
现在,我正在执行以下操作:
问题是该类包含对受限类的API调用,尽管我更改了Eclipse编译器设置(窗口->首选项-> Java->编译器->错误/警告->不建议使用和受限的API->禁止引用(访问规则) :错误->警告)以允许访问项目,有时只会编译。如果无法编译,则会出现“找不到符号”错误。
编辑:
这是您要求的详细信息:
相关性:http : //mvnrepository.com/artifact/com.sun.xml.wss/xws-security/3.0
类:EncryptionProcessor
必要更改:
// Change line 1053 FROM:
// _dataEncryptor = XMLCipher.getInstance(dataEncAlgo, _dataCipher);
// TO:
_dataEncryptor = XMLCipher.getInstance(dataEncAlgo);
Run Code Online (Sandbox Code Playgroud)编辑2:
Maven构建错误:
[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
Run Code Online (Sandbox Code Playgroud)
Ste*_* S. 10
这是详细的指南,描述了我到底做了什么:
配置新项目的 Maven 设置(重要:使用相同的组和工件 ID,仅更改版本号)
<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>
Run Code Online (Sandbox Code Playgroud)添加有缺陷的 JAR 的依赖项
<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>
Run Code Online (Sandbox Code Playgroud)在需要修复的类的同一个包中创建Java文件
package com.sun.xml.wss.impl.apachecrypto;
public class EncryptionProcessor {
// The FIX goes here
}
Run Code Online (Sandbox Code Playgroud)添加 Maven 阴影构建插件来处理修补 JAR 文件的创建(这不是处理此类任务的唯一插件 - 例如 dependency:unpack)
<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>
Run Code Online (Sandbox Code Playgroud)根据需要在其他项目中包含已修补的 JAR(注意:如果您遇到 ClassNotFoundExceptions 或类似错误,请执行以下操作:右键单击项目 -> 属性 -> Maven -> “解决工作空间项目的依赖关系”:false)
如果您不熟悉 Maven。这是完整的 pom.xml:http://pastebucket.com/88444
一般解决方案:
pom.xml,例如从3.0到3.0-patched类似于 Steven S. 的回答,但使用maven-dependency-plugin。基于这篇博文。
我更改了修补库的名称(不是版本),但这取决于您的需求,哪种更适合您。
对原始库的依赖应标记为<optional>true</optional>. 否则,依赖你打补丁的库的项目也将依赖原始库,这意味着打补丁和原始版本都会在类路径上,这会导致各种问题。
如果您的项目是子项目,您仍然可以使用与父 pom 完全不同的 groupId 和版本。没关系。
您可以从解包中排除您修补的类,但这可能没有必要,因为 Maven 将首先解压原始库,然后编译您的新版本,这意味着原始类将被覆盖。好的!
<?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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5271 次 |
| 最近记录: |