Can I set a breakpoint in a dynamically loaded .jar (with ClassLoaders)?

I am writing a program that loads a .jar for a Minecraft game, does some ASM trickery, dumps them into a .class files folder, and loads that folder with ClassLoader (then launches the game). I want to set a breakpoint in one of these class files to aid debugging. Adding Minecraft.jar as a dependency in IntelliJ breaks the program (since it doesn't load the modified class).

How to do this, if possible?

+3


source to share


3 answers


You can do this, but not directly. What you need to do is place a breakpoint at the side of YOUR code that calls (uses) the JAR in the question, and then STEP INTO in the JAR code.



+1


source


usually debug information is added (or not) to javac

( see options info ). So if you don't have the source of the code, or even if you do, but the bytecode was compiled without debug information, there is no way to do it.



0


source


Option one: you can add the JAR as a dependency, but change its type to Provided.

If that doesn't work: I am assuming you have a lot of libraries configured in your project. Try adding your Minecraft jar sources to any of these libraries (Project Structure -> Libraries -> Add -> select a jar or directory with source files). Now, using Go to class, open the class where you want to set a breakpoint and set that breakpoint. Unless IntelliJ IDEA refuses to do this, and if you ASM manipulation does not remove the debug information when the class is dynamically loaded at runtime, the debugger stops at a breakpoint.

0


source







All Articles