简体   繁体   English

Java最小化依赖关系

[英]Java Minimize Dependencies

I have a situation where there is a small piece of Java code that has a large number of jars that it depends on. 我有一种情况,其中有一小段Java代码,它依赖于大量的jar。 However, the dependencies inside these jars are very shallow. 但是,这些jar中的依赖关系非常浅。 In most cases it only depends on a jar for a single interface. 在大多数情况下,它仅依赖于单个界面的jar。

Instead of distributing all of the jars with the application, I would like to just distribute the specific class files inside the jars that it actually uses. 我不想将所有jar分发给应用程序,而是将特定的类文件分发到它实际使用的jar中。 The reason for this is to conserve space (this code will live in an applet). 这样做的原因是为了节省空间(此代码将存在于applet中)。

Does anyone know of a tool or method to do this automatically? 有谁知道自动执行此操作的工具或方法? Assuming all of the dependencies are static, this seems entirely possible. 假设所有依赖项都是静态的,这似乎完全有可能。 Any ideas? 有任何想法吗?

Classdepandjar will strip down a codebase to the essential classes. Classdepandjar将删除代码库到基本类。 It's used in the Jini world for delivering optimally-sized jars, but there's nothing Jini-specific about it. 它在Jini世界中用于提供最佳尺寸的罐子,但没有Jini特有的关于它。

Available as an Ant task. 可用作Ant任务。

As far as I know, this is maven only, but it's a good start 据我所知,这只是maven,但这是一个好的开始

Maven Shade Plugin : This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - ie rename - the packages of some of the dependencies. Maven Shade插件 :这个插件提供了将工件打包在超级jar中的功能,包括它的依赖关系和阴影 - 即重命名 - 一些依赖项的包。

ProGuard does shrinking/optimizingh and also obfuscation. ProGuard确实缩小/优化并进行混淆。 I think you can config it to do just one or the other. 我认为你可以配置它只做一个或另一个。

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

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