如何使用 jarjar 从默认包中重新打包 .class 文件?

发布于 2024-12-16 21:55:06 字数 389 浏览 2 评论 0原文

是否可以从默认包中移动 jar 中的 .class 文件 到另一个命名包以便我可以导入和使用它们?

在这里浏览其他问题后,我认为 jarjar 可能正是我要寻找的, 但我不知道如何使用它。

所以我的问题是如何使用 jarjar 将 .class 文件从默认包重新打包到另一个命名包?

编辑:我想澄清一些事情 - 我没有要重新打包的 jar 的来源, 所以我不知道如何重新编译代码。 混淆和反思是不可能的。

EDIT2:使用 jarjar 看起来非常简单:) java -jar jarjar.jar process Rules.rules in.jar out.jar

Rules.rules 看起来像这样: 规则一下net.ylivay.src.a

问题解决了!

Is it possible to move the .class files in a jar from the default package
to another named package so that I can import and use them?

After browsing other questions here, I think jarjar might be exactly what im looking for,
but I don't have any idea how I can use it.

So my question is how to use jarjar to repackage .class files from the default package to another named package?

EDIT: I want to clarify something - I do not have the sources of the jar I want to repackage,
so I don't know how I could recompile the code.
Obfuscation and reflection is out of the question.

EDIT2: It appears its extremely simple to do using jarjar :)
java -jar jarjar.jar process rules.rules in.jar out.jar

rules.rules look something like this:
rule a net.ylivay.src.a

Problem solved!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

压抑⊿情绪 2024-12-23 21:55:06

要将类移动到不同的包中,您不仅需要更改它们在 jar(或文件系统)目录结构中的位置,还需要更改源文件中的 package 声明,然后重新编译类。

您或许应该看看 Eclipse 等 IDE 中提供的强大重构工具,而不是尝试重新打包 jar,这使得此类事情变得简单。但既然你说(在更新你的问题时)你没有源文件,那是不可能的。

另一种方法是创建代理类,使用反射调用默认包中所需的代理类。但这不仅令人不快,而且你说反思是不可能的。

所以你不能做你想做的事。

To move classes into a different package, you not only need to change their location in the jar (or filesystem) directory structure, you also need to change the package declaration in the source files and then recompile the classes.

Instead of trying to repackage a jar, you should probably look at the powerful refactoring tools available in IDEs like Eclipse, which make this kind of thing simple. But since you say (in update to your question) that you don't have the source files, that is not possible.

The alternative would be to create proxy classes which invoke the ones you need in the default package using reflection. But not only is that unpleasant, but you say that reflection is out of the question.

So you cannot do what you want to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文