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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值