TransWikia.com

How to change source code in maven dependency?

Stack Overflow Asked on December 25, 2021

I have a maven project with a bunch of dependencies, one of which I’d like to print a line to console to called pulsar-log4j2-appender. I tried opening the .class file in question by following in Intellij:

External Libraries | Maven: org.apache.pulsar:pulsar-log4j2-appender:2.6.0 | pulsar-log4j2-appender-2.6.0.jar | org.apache.pulsar.log4j2.appender | PulsarManager.class

When I try to add a System.out.println statement, Intellij says the file is read only:

enter image description here

2 Answers

Powered by Java bytecode decompiler plugin, IntelliJ decompiles Java bytecode into human-readable Java code When you try to open .class extension

Now, you're actually viewing Java decompiled bytecode(can't be edited inside the IDE), not actual Java code (.java extension).

The solution would be to modify the source code itself and rebuild it.

More info: https://blog.jetbrains.com/idea/2020/03/java-bytecode-decompiler/

Answered by Hamza Belmellouki on December 25, 2021

You cannot change code in external Maven dependencies.

You can debug them, though, with the debugger of your IDE and watch the values you are interested in.

If you really want to change the code, you need to find the project (e.g. on Github), check it out and build it yourself.

Answered by J Fabian Meier on December 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP