简体   繁体   English

如何更改 maven 依赖项中的源代码?

[英]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 .我有一个带有一堆依赖项的 maven 项目,其中一个我想在控制台中打印一条名为pulsar-log4j2-appender的行。 I tried opening the.class file in question by following in Intellij:我尝试在 Intellij 中打开有问题的 .class 文件:

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:当我尝试添加 System.out.println 语句时,Intellij 说该文件是只读的:

在此处输入图像描述

You cannot change code in external Maven dependencies.您不能更改外部 Maven 依赖项中的代码。

You can debug them, though, with the debugger of your IDE and watch the values you are interested in.不过,您可以使用 IDE 的调试器对它们进行调试,并观察您感兴趣的值。

If you really want to change the code, you need to find the project (eg on Github), check it out and build it yourself.如果您真的想更改代码,您需要找到项目(例如在 Github 上),检查并自己构建它。

Powered by Java bytecode decompiler plugin, IntelliJ decompiles Java bytecode into human-readable Java code When you try to open .class extension 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).现在,您实际上查看的是 Java 反编译的字节码(无法在 IDE 中编辑),而不是实际的 Java 代码( .java扩展名)。

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/更多信息: https://blog.jetbrains.com/idea/2020/03/java-bytecode-decompiler/

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

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