我intellij中的jar资源文件是只读的,我需要对其进行编辑 [英] My jar resource files in intellij are read only and I need to edit them

查看:1956
本文介绍了我intellij中的jar资源文件是只读的,我需要对其进行编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了几个小时,但都没有成功地编辑我正在用作库的jar中的Java文件.我已将资源标记为内容根目录和源根目录,但是仍然无法编辑jar中的代码.该项目可以编译并正确运行,但是我需要对资源文件进行调整,但是不能;我尝试了所有我能想到的项目结构.只是不可能吗?感谢所有帮助.

I have tried unsuccessfully for a few hours now to edit the java files in a jar I am using as a library. I have marked the resource as a content root and as a source root but I am still unable to edit the code in the jars. The project compiles and runs correctly but I need to make an adjustment to a resource file and cannot; I have tried every project structure I could think of. Is it just impossible? All help is appreciated.

推荐答案

不建议编辑JAR文件.从可再现性 1 的角度来看,最好:

It is not recommended to edit JAR files. From the perspective of reproducibility1, it is better to:

  1. 掌握该库的源代码树
  2. 将其检入您的版本控制中(或将其存储在Github上)
  3. 修改并构建它
  4. 使用生成的JAR代替原始的JAR
  1. Get hold of the source tree for the library
  2. Check it into your version control (or fork it on Github)
  3. Modify and build it
  4. Use the resulting JAR instead of the original JAR

另一种方法是通过使用资源的替代版本创建另一个JAR,并将其放在应用程序类路径中的较早位置,以覆盖"您要进行的更改.

Another approach is to "overlay" the changes you want to make by creating a another JAR with the alternative version of the resources and placing it earlier in the application classpath.

但是,如果这些都不适合您,则可以从命令行使用jar命令来修改JAR文件:

But if neither of those works for you, you can use the jar command from the command line to modify a JAR file:

  1. 使用jar -x ...将文件提取到临时目录树中
  2. 应用需要对树进行的任何更改
  3. 使用jar -c ....从树中创建新的JAR.
  1. Use jar -x ... to extract the files to a temporary directory tree
  2. Apply what ever changes need to be made to the tree
  3. Use jar -c .... to create a new JAR from the tree.

有关更多信息,请阅读jar命令的手册条目.如果您不是原始签名者,则使用原始密钥对新的JAR进行签名将是一个问题,但是我怀疑这与您是否相关.

Read the manual entry for the jar command for more details. Signing the new JAR with the original keys would be an issue if you are not the original signer, but I doubt that that is relevant to you.

1-关键是,下一个维护您的代码的人需要知道您对编辑"的库JAR所做的操作,以防他需要对另一个版本的JAR执行相同的过程.如果您手动操作,他别无选择,只能对原始版本和您编辑版本之间的差异进行法医比较.并假设仍可以获取原始JAR.请注意,当您完全忘记自己所做的事情时,几个月或几年后,下一个家伙"可能就是您.

这篇关于我intellij中的jar资源文件是只读的,我需要对其进行编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆