doctopus
doctopus

Reputation: 5647

How to change source code in maven dependency?

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

Upvotes: 0

Views: 2012

Answers (2)

Hamza Belmellouki
Hamza Belmellouki

Reputation: 2728

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/

Upvotes: 3

J Fabian Meier
J Fabian Meier

Reputation: 35805

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.

Upvotes: 6

Related Questions