简体   繁体   English

编译从现有jar中编辑的单个类文件,没有依赖项

[英]Compiling a single class file edited from existing jar with no dependencies

I need to edit a single class file from within a jar. 我需要从jar中编辑单个类文件。

I have successfully extracted the class file from the jar, and I have decompiled it and found the logic I need to change. 我已经成功地从jar中提取了类文件,并对其进行了反编译,发现需要更改的逻辑。

However, I'm unable to recompile this class file, because it imports libraries I don't have and don't know where to get ( netbeans and iharder ). 但是,我无法重新编译该类文件,因为它会导入我没有的,不知道从何处获取的库( netbeansiharder )。

The needed files should all be within the jar, right? 所需的文件都应该在jar中,对吗? Can I use the jar for this purpose? 我可以用这个罐子吗?

I do not understand much of Java's overarching syntax, so anything related to packages or jar file structure might go over my head... 我不太了解Java的总体语法,因此与包或jar文件结构相关的任何事情都可能困扰我……

The JVM just needs to be able to find the dependencies at runtime. JVM仅需要能够在运行时找到依赖项。 Often, they'll be installed in a standard location (the classpath), rather than being bundled with the jar that uses them. 通常,它们将安装在标准位置(类路径),而不是与使用它们的jar捆绑在一起。 However, you could theoretically even do something like download dependencies at runtime and load them via a classloader. 但是,从理论上讲,您甚至可以在运行时执行诸如下载依赖项之类的操作,然后通过类加载器进行加载。

Apart from that, decompiling and recompiling is often not a good idea, since decompilation is a lossy and error prone process. 除此之外,反编译和重新编译通常不是一个好主意,因为反编译是一个有损且容易出错的过程。 It generally only works in simple cases, and has limitations, as you've discovered. 正如您所发现的,它通常仅在简单情况下有效,并且有局限性。

If you understand Java bytecode, you can edit the class by disassembling it with Krakatau , editing the .j file, and then reassembling. 如果您了解Java字节码,则可以通过使用Krakatau对其进行反汇编,编辑.j文件然后进行重新汇编来编辑该类。 This allows you to edit any classfile without needing to compile, meaning you don't need the dependencies. 这使您无需编译即可编辑任何类文件,这意味着您不需要依赖项。 It also works no matter how complicated the class is, and even works on obfuscated classes. 无论该类有多复杂,它也可以工作,甚至适用于混淆的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM