Java - 如何减小第三方 jar 的大小以减小应用程序的大小

标签 java jar dependencies

I am developing a java web application and that includes an applet. That applet is dependent on two jar files:

  • JFreeChart (for plotting graphs at the client side) - 1.7 mb(size of jar file)
  • MySqlJdbcConnector (for storing data, captured at the client side, to a remote database) - .7 mb (size of jar file)

Now, the problem is the size of above two jar files. The total size of my applet jar (myApplet.jar) is 2.5 mb out of which 2.4 mb is because of the above two jar files.

I am not using all the classes in those jar files. Specifically, for jfreechart, I am using a very small number of classes from that library.

==============================问题========= =============================

Q1. 为了创建 myApplet.jar 文件,我所做的是解压两个 jar 文件(jfreechart 和 mySQLJdbcConnector),然后打包解压后的版本jar 文件与我的 applet 代码的源代码一起创建一个 jar 文件(即 myApplet.jar)。 将第三方 jar 文件与您的 applet 代码打包的正确方法吗?有什么方法可以优化它吗?

Q2. 我试图找到我在我的应用程序中使用的 jfreechart 库类的依赖项,以便仅将那些依赖项打包到 myApplet.jar 中。为此,我使用了 DependencyAnalyzer找到所有类的依赖关系。但后来我发现很难手动执行此操作,因为每个类(我在我的应用程序中使用的 jfreechart 类)都有很多依赖项,而且我正在使用大约 15 个 jfreechart 类,因此对每个类执行此操作将非常困难。那么对此有什么建议吗?

问题 3.开发人员遇到的这种情况是否很常见,或者我错过了什么,因此我必须这样做?

最佳答案

我建议尝试 ProGuard .您可以排除未使用的部分 jar 文件。

关于Java - 如何减小第三方 jar 的大小以减小应用程序的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5580221/

相关文章:

java - Java 和 Python 的最佳 GUI 工具包/框架

java - tomcat 显示 org.apache.catalina.LifecycleException

java - setUp/tearDown (@Before/@After) 为什么我们在 JUnit 中需要它们?

java - IntelliJ 正确使用库

java - 获取 JAR 文件的位置

c# - 为使用 Process.Start 启动的 exe 指定 DLL?

java - 如何解决未解析的依赖关系 ':app@debug/compileClasspath' : Could not resolve com. google.android.gms :play-services-base:[15. 0.0, 16.0.0)

java - 使用木槌主题建模相同数据的不同主题分布

ant - Apache Ant/NetBeans - build.xml 中的语句将 dist/myfile.jar 复制到另一个文件夹

java - 为部署到 heroku tomcat 的 Java Web WAR 找不到添加依赖项的类