Java - 如何减少第三方jar的大小以减小应用程序的大小 [英] Java - How to reduce the size of third-party jars to reduce the size of your application

查看:710
本文介绍了Java - 如何减少第三方jar的大小以减小应用程序的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在开发一个 java Web应用程序,其中包括一个小程序。该小程序是
,取决于两个jar文件:




  • JFreeChart (用于在客户端绘制图形) - 1.7 mb(
    大小的jar文件)

  • MySqlJdbcConnector(用于存储数据,在客户端捕获到
    a远程数据库) - .7 mb(
    jar文件的大小)



现在,问题是上面的
两个jar文件的大小。我的
applet jar (myApplet.jar)的总大小是 2.5
mb
,其中 2.4 mb
由于上述两个jar文件。



我没有在
中使用这些jar文件中的所有类。具体来说,对于
jfreechart ,我使用的是
库中的少量类。


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



Q1。为了创建 myApplet.jar 文件,我所做的是我已经解压缩了这两个jar文件(jfreechart和mySQLJdbcConnector),然后打包解压缩的jar文件版本我的小程序代码的源代码创建一个单一的jar文件( ie myApplet.jar)。是否是使用您的applet代码打包第三方jar文件的正确方法?有没有什么办法可以优化这个?



Q2。我试图找到我的jfreechart库的依赖关系在我的应用程序中使用,以便仅在 myApplet.jar中打包这些依赖关系。为此目的,我使用 DependencyAnalyzer 来查找所有类的依赖关系。但后来我发现很难手动执行,因为每个类(我在应用程序中使用的jfreechart类)都有很多依赖关系,而且我使用了15个类的jfreechart,所以这样做对于每一个类将是非常困难的。所以有任何建议吗?



Q3。这种情况很常见,开发人员遇到或我缺少一些东西,因为我必须做这个?

解决方案

A1:



或使用Eclipse或任何其他IDE自动打包您的Applet。但是你的方式也是正确的



A2:



我不会手动进行这些操作。查找传递性依赖非常复杂。可能 darioo 的答案是更好的方法。



A3:



<这是非常普遍的。几个提示:



您可以随时重新构建没有调试信息的第三方库。这应该会稍微减小这些库的大小。



另一方面,也许你不应该从你的小程序直接连接到数据库。您可以创建一个RMI接口(或类似的内容)将SQL和结果数据传输到实际执行SQL的应用程序服务器。如果您没有在安全的Intranet中运行此应用程序,这是您的小程序的重要安全方面。


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.

==============================Questions======================================

Q1. For creating myApplet.jar file, what I have done is I have unzipped both of the jar files (jfreechart and mySQLJdbcConnector) and then packed the unzipped version of the jar files with the source code of my applet code to create one single jar file (i.e myApplet.jar). Is it the correct way of packing third party jar files with your applet code? Is there any way by which I can optimize this?

Q2. I tried to find the dependencies of the classes of jfreechart library which I am using in my application so as to pack only those dependencies in myApplet.jar. For that purpose, I used DependencyAnalyzer to find the dependencies of all the classes. But later I found it difficult to do so manually because every class (class of jfreechart that I am using in my application) has lot of dependencies and I am using some 15 classes of jfreechart so doing this for every class will be very difficult. So any suggestion on this?

Q3. Is this situation very common that developers encounter or I am missing something because of which I have to do this?

解决方案

A1:

You can create an ant script or use Eclipse or any other IDE to automatically package your applet. But your way is correct, too

A2:

I wouldn't do these things manually. Finding transitive dependencies is very complex. Maybe darioo's answer is a better way to do this.

A3:

This is very common indeed. A couple of hints:

You can always re-build those third party libraries without debug information. That should slightly decrease the size of those libraries.

On the other hand, maybe you shouldn't have a direct connection from your applet to a database. You could create an RMI interface (or something similar) to transfer your SQL and result data to an application server, which actually executes your SQL. This is an important security aspect for your applet, if you don't run this in a safe intranet.

这篇关于Java - 如何减少第三方jar的大小以减小应用程序的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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