仅使用主类中的递归依赖类构建 JAR 文件

发布于 2024-12-03 03:46:59 字数 106 浏览 1 评论 0原文

有没有一种简单的方法来生成 JAR 文件,该文件仅包含依赖于某个“主”类的传递类(当然省略了反射)。 我想向其他人提供我的应用程序的一小部分,但不想导出整个应用程序。

谢谢, M。

is there a simple way to generate a JAR file, that contains only the classes that depend transitive from a certain "main" class (reflection omitted of course).
I want to provide a little part of my application to someone else but do not want to export the whole application.

Thanks,
M.

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

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

发布评论

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

评论(1

回忆躺在深渊里 2024-12-10 03:46:59

最简单的方法可能是使用像 yGuard 这样的工具,它“...通过依赖关系分析提供复杂的代码压缩功能”。这也可以解决同样的问题,您给它一个入口点,它会执行依赖性分析来确定哪些类可以从 Jar 中排除。

然而,我自己也曾多次思考过这个问题,并想亲自尝试一下挑战。所需要做的就是解析 Java 源文件的导入语句并构建一个类如何相互交互的依赖关系图。应递归扫描主类中的每个引用,直到组装出完整的图。然后,一旦图形被组装起来,就会以某种打包逻辑可以处理的方式输出它(或者如果你够大胆,JDK 有自己内置的 Jar 创建/修改代码来自己完成它)。当然,这种方法需要编写这个自定义实用程序,并且还会错过代码中完全限定的类引用。

Probably the easiest approach is using a tool like yGuard which "...provides elaborate code shrinking functionality through dependency analysis." This would also solve the same problem where you give it an entry point, and it performs dependency analysis to work out which classes can be excluded from the Jar.

However, I have throught about this problem myself a few times and fancied having a go at it myself for the challenge. All it would take would be to parse the import statements of Java source files and build a dependncy graph of how the classes interact with each other. Each reference from the main class should be recursively scanned until a complete graph is assembled. Then once the graph is assembled it would be a case of outputting this in a way that some packaging logic could process (or if you are feeling daring, the JDK has its own built in Jar creating/modifying code to do it yourself). Granted, this approach would require writing this custom utility and would also miss fully qualified class references in the code.

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