Class 在maven程序集之前替换类文件
我面临着一个非常独特的情况,需要一些建议: 我正在做一个依赖于同一家公司的其他项目的项目,现在我需要对依赖项进行一些修改。 我遇到的问题是,依赖项的源代码已经丢失,因此我唯一拥有的就是存储库中的maven依赖项,以及相应的jar文件。 除此之外,Jar文件中的一些类是使用JiBX解析器创建的,映射了一些我没有的XSD文件,生成的类是合成的,我发现没有反编译器能够正确处理它们 所有这一切的唯一好处是,我需要更改的类可以正确地反编译,因此选择了以下内容:Class 在maven程序集之前替换类文件,class,maven,jar,resources,package,Class,Maven,Jar,Resources,Package,我面临着一个非常独特的情况,需要一些建议: 我正在做一个依赖于同一家公司的其他项目的项目,现在我需要对依赖项进行一些修改。 我遇到的问题是,依赖项的源代码已经丢失,因此我唯一拥有的就是存储库中的maven依赖项,以及相应的jar文件。 除此之外,Jar文件中的一些类是使用JiBX解析器创建的,映射了一些我没有的XSD文件,生成的类是合成的,我发现没有反编译器能够正确处理它们 所有这一切的唯一好处是,我需要更改的类可以正确地反编译,因此选择了以下内容: <build> <plug
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>${project.groupId}:${project.artifactId}</include>
<include>TheDamnedProject:WithoutSources</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>TheDamnedProject:WithoutSources</artifact>
<includes>
<!-- These classes will be taken directly from dependency JAR -->
<include>my/package/ClassWhichCouldNotBeDecompiled1.class</include>
<include>my/package/ClassWhichCouldNotBeDecompiled2.class</include>
<include>my/package/ClassWhichCouldNotBeDecompiled3.class</include>
<include>my/package/ClassWhichCouldNotBeDecompiled4.class</include>
</includes>
</filter>
<filter>
<artifact>${project.groupId}:${project.artifactId}</artifact>
<excludes>
<!-- These classes will be overridden by the ones inside the JAR -->
<exclude>my/package/ClassWhichCouldNotBeDecompiled1.class</exclude>
<exclude>my/package/ClassWhichCouldNotBeDecompiled2.class</exclude>
<exclude>my/package/ClassWhichCouldNotBeDecompiled3.class</exclude>
<exclude>my/package/ClassWhichCouldNotBeDecompiled4.class</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
- 我反编译了整个jar文件,最后得到了一些类( JiBx)中包含空的或错误实现的方法
- 我注释掉了使用存根对象的错误方法的主体,将所需的更改应用到正确的类并重新编译
- 我获取了旧的Jar文件,打开它,并手动将旧类替换为新类
- 像往常一样编译所有内容,将所有已编译的类文件 进入目标文件夹
- 从目标文件夹中删除存根类文件,并用旧的预编译类文件替换它们
- 把罐子打包
my.project.domain.JiBX__c_GeneratedObfuscatedClass1.java
my.project.domain.JiBX__c_GeneratedObfuscatedClass2.java
my.project.domain.JiBX__c_GeneratedObfuscatedClass3.java
my.project.domain.CustomizableClass1.java
my.project.domain.CustomizableClass2.java
my.project.domain.CustomizableClass3.java
JiBX类没有作为依赖项正确导入,如果我尝试将任何CustmizableClasses放入项目源代码中,并让JiBX类处于依赖项中,编译器会报告缺少的方法
我还尝试使用建议的Shade插件,但由于我需要将JiBX类包含到源路径中,因此我最终不得不将jar依赖项和编译的自定义类包含到包JiBX类中,但跳过jar dep和编译的JiBX类中的自定义类
我看起来可以,但我承认我还是没有找到方法。
任何线索都将受到欢迎
更新2(分辨率)
我在这里解释了我最终是如何按照建议使用shade插件实现这一点的,以防其他人也需要这样做:
我最终在同一个包中创建了一个包含反编译类的项目,并将不希望反编译的方法注释掉
在pom.xml中,我添加了以下内容:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>${project.groupId}:${project.artifactId}</include>
<include>TheDamnedProject:WithoutSources</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>TheDamnedProject:WithoutSources</artifact>
<includes>
<!-- These classes will be taken directly from dependency JAR -->
<include>my/package/ClassWhichCouldNotBeDecompiled1.class</include>
<include>my/package/ClassWhichCouldNotBeDecompiled2.class</include>
<include>my/package/ClassWhichCouldNotBeDecompiled3.class</include>
<include>my/package/ClassWhichCouldNotBeDecompiled4.class</include>
</includes>
</filter>
<filter>
<artifact>${project.groupId}:${project.artifactId}</artifact>
<excludes>
<!-- These classes will be overridden by the ones inside the JAR -->
<exclude>my/package/ClassWhichCouldNotBeDecompiled1.class</exclude>
<exclude>my/package/ClassWhichCouldNotBeDecompiled2.class</exclude>
<exclude>my/package/ClassWhichCouldNotBeDecompiled3.class</exclude>
<exclude>my/package/ClassWhichCouldNotBeDecompiled4.class</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
org.apache.maven.plugins
maven阴影插件
2
包裹
阴凉处
${project.groupId}:${project.artifactId}
DamnedProject:无外包
DamnedProject:无外包
我的/包/类无法编译1.class
我的/包/类无法编译2.class
我的/包/类无法编译3.class
我的/包/类无法编译4.class
${project.groupId}:${project.artifactId}
我的/包/类无法编译1.class
我的/包/类无法编译2.class
我的/包/类无法编译3.class
我的/包/类无法编译4.class
谢谢
Carles以下是我将如何做到这一点:
- 为此Jar文件创建一个新的Maven项目,打包类型为Jar
- 将原始Jar文件作为依赖项包括在内
- 在src文件夹中添加一个反编译的.java文件
groupId
和artifactId
,然后修改