简体   繁体   中英

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

I need to edit a single class file from within a jar.

I have successfully extracted the class file from the jar, and I have decompiled it and found the logic I need to change.

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 ).

The needed files should all be within the jar, right? 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...

The JVM just needs to be able to find the dependencies at runtime. Often, they'll be installed in a standard location (the classpath), rather than being bundled with the jar that uses them. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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