将fastxml.jackson类重定位到my.package.fastxml.jackson [英] Relocating fastxml.jackson classes to my.package.fastxml.jackson
问题描述
我正在尝试将包从com.fasterxml.jackson重新定位到我自己的包中(即mypackage.com.fasterxml.jackson),然后在我拥有的另一个JAR中使用它。
I'm trying to relocate the packages from "com.fasterxml.jackson" into my own package (ie, "mypackage.com.fasterxml.jackson") and then consume it in another JAR which I own.
我设法使用此配置运行maven-shade插件:
I've managed to run the maven-shade plugin to do it using this configuration:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>mypackage.com.fasterxml.jackson</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
我面临的问题是当我尝试使用它时,由于某些原因Eclipse不断添加对原始jackson(mypackage.com.fasterxml.jackson)的依赖而不是新的。
The problem that I'm facing is when I try to consume it, from some reason Eclipse keeps adding a dependency to the original jackson ("mypackage.com.fasterxml.jackson") and not the new one.
为了清楚起见,我的设置是:
- Jar X在ThirdPartyArtifcats中具有依赖关系。
- ThirdPartyArtifcats引用Jackson并运行maven-shade插件,因此它包含Jackson的修改版本(mypackage.com.fasterxml.jackson)。
Just to be clear, my setup is: - Jar X have a dependency in ThirdPartyArtifcats. - ThirdPartyArtifcats references Jackson and run the maven-shade plugin, thus it contains a modified version of Jackson (mypackage.com.fasterxml.jackson).
我尝试在Jar X中使用Jackson的ObjectMapper,Eclipse不断提供对原始jackson的引用。
When I try to use Jackson's ObjectMapper in Jar X, Eclipse keeps giving a reference to the original jackson.
我将非常感谢你的帮助!
I'll appreciate your help!
推荐答案
最后我使用了JarJar并创建了一个修改过的JAR。然后我已经为我的代码添加了一个依赖项并手动更新它,所以它现在与修改后的包而不是原始包相关。
In the end I've used JarJar and created a modified JAR. Then I've added a dependency to my code and updated it manually so it now relates to the modified package instead of the original package.
这是一个描述我的代码的过程已完成:
Here's a procedure describing what I've done:
在这个例子中,我们将把包从com.fasterxml.jackson改为io.kuku.dependencies.com.fasterxml.jackson。
- 源JAR称为jackson-databind-2.6.4.jar,新的修改(目标)JAR称为kuku-jackson-databind-2.6.4.jar。
- jarjarJAR文件版本为1.4
In this example we'll be changing the package from "com.fasterxml.jackson" to "io.kuku.dependencies.com.fasterxml.jackson". - The source JAR is called "jackson-databind-2.6.4.jar" and new modified (target) JAR is called "kuku-jackson-databind-2.6.4.jar". - The "jarjar" JAR file is in version 1.4
-
创建rules.txt文件。该文件的内容应该是(观察'@'字符前的句号):
rule com.fasterxml.jackson。** io.kuku.dependencies.com.fasterxml.jackson。@ 1
Create a "rules.txt" file. The contents of the file should be (watch the period before the '@' character): rule com.fasterxml.jackson.** io.kuku.dependencies.com.fasterxml.jackson.@1
运行以下命令:
java -jar jarjar-1.4.jar process rules.txt jackson-databind-2.6.4.jar kuku-jackson-databind- 2.6.4.jar
Run the following command: java -jar jarjar-1.4.jar process rules.txt jackson-databind-2.6.4.jar kuku-jackson-databind-2.6.4.jar
将修改后的JAR安装到本地存储库
在这种情况下,我正在安装位于c:\ my-jars \文件夹中的3个文件。
Installing the modified JARs to the local repository
In this case I'm installing 3 files located on "c:\my-jars\" folder.
mvn install:install-file -Dfile = C:\ my-jars\kuku-jackson-annotations-2.6.4.jar -DgroupId = io.kuku.dependencies -DartifactId = kuku-jackson-annotations -Dversion = 2.6.4 -Dpackaging = jar
mvn install:install-file -Dfile=C:\my-jars\kuku-jackson-annotations-2.6.4.jar -DgroupId=io.kuku.dependencies -DartifactId=kuku-jackson-annotations -Dversion=2.6.4 -Dpackaging=jar
mvn install:install-file -Dfile = C:\ my-jars\kuku-jackson-core-2.6 .4.jar -DgroupId = io.kuku.dependencies -DartifactId = kuku-jackson-core -Dversion = 2.6.4 -Dpackaging = jar
mvn install:install-file -Dfile=C:\my-jars\kuku-jackson-core-2.6.4.jar -DgroupId=io.kuku.dependencies -DartifactId=kuku-jackson-core -Dversion=2.6.4 -Dpackaging=jar
mvn install:install- file -Dfile = C:\ my-jars\kuku -jackson-databind-2.6.4.jar -DgroupId = io.kuku.dependencies -DartifactId = kuku-jackson-annotations -Dversion = 2.6.4 -Dpackaging = jar
mvn install:install-file -Dfile=C:\my-jars\kuku-jackson-databind-2.6.4.jar -DgroupId=io.kuku.dependencies -DartifactId=kuku-jackson-annotations -Dversion=2.6.4 -Dpackaging=jar
在这个例子中,这是项目pom中的dependencies元素:
In this example, this is the "dependencies" element in the projects pom:
<dependencies>
<!-- ================================================== -->
<!-- kuku JARs -->
<!-- ================================================== -->
<dependency>
<groupId>io.kuku.dependencies</groupId>
<artifactId>kuku-jackson-annotations</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>io.kuku.dependencies</groupId>
<artifactId>kuku-jackson-core</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>io.kuku.dependencies</groupId>
<artifactId>kuku-jackson-databind</artifactId>
<version>2.6.4</version>
</dependency>
这篇关于将fastxml.jackson类重定位到my.package.fastxml.jackson的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!