1

I am relatively newbie in Java. While I was developing an applet, I made as well a library containing a series of functions to be used in a server side application.
I realized that perhaps I could shrink the jar size, by exporting only the classes, from the library, i am using inside the applet.
Is there any way to do it semi-automatic?
Some app that could point me the used classes, or something likewise...

EDIT :
Perhaps I could not express it right.
What I want to do is get which classes from this library of mine I am using for the applet.
I can do it manually, as I am doing it right now, but I would rather use a tool that would help me to create a build out of it, telling which classes I am working with, instead of a guess which I am using. I am using eclipse, but I am aware of ant. I am aware on how to build an applet, or a jar. My problem is to make it more efficiently.

marcelo-ferraz
  • 3,147
  • 4
  • 38
  • 55

1 Answers1

0

This greatly depends on the tool you are using for building the jar-Files. But probably those tools already have a mechanism in place to exclude classes / files from the jar-File. A classic tool would be ant. If you are using ant, this link should provide information to you: How to exclude a directory from ant fileset, based on directories contents

If you are using a different tool, please edit your question.

On a sidenote: Are you really sure you want to use a Java Applet for a Client/Server Application. If you prefer an applet because you can distribute it easily, consider using Java Web Start.

Community
  • 1
  • 1
Matthias
  • 3,582
  • 2
  • 30
  • 41
  • Thanks, Mathias, but my problem is actually to guess which classes from the library I am using, in a automatic fashion. – marcelo-ferraz Feb 25 '13 at 10:46
  • To build is the minor problem. I want to make a lite version of my lib, to be used inside the applet, optimizing the size and then its loading. – marcelo-ferraz Feb 25 '13 at 10:48
  • Aah, now I understand the problem more clearly. An automatic solution is not easy as classes can be loaded at Runtime (e.g. by reflection). You could of course overwrite the Classloader. Every time a class is loaded, you could e.g. print the name of the class to the console. It then gets complicated if classes are loaded at a later time, e.g. when you (or the libs you use) throw an Exception somewhere. I guess that Java Web Start is not an option? There you can cache the jar-Files locally and thus save download/startup time and still you can distribute your application with ease. – Matthias Feb 25 '13 at 12:06
  • I forgot to mention it, the applet is going to interact with different server sides, per instance an ASP.Net, php and Java. – marcelo-ferraz Feb 25 '13 at 18:36
  • One of the requirements for using a jws is the use of a jnlp, and perhaps the server side will have no java, at all... – marcelo-ferraz Feb 25 '13 at 18:52
  • And I plan to use heavily javascript with java – marcelo-ferraz Feb 25 '13 at 18:52
  • What about that: store the lib (jar) in the server, override the class loader, in the applet, and use it to download the classes during the code usage. What do you think? is it possible? – marcelo-ferraz Feb 25 '13 at 19:13
  • But that I suppose it will download the whole library, right? – marcelo-ferraz Feb 25 '13 at 19:21
  • JWS needs a JNLP, but there does not need to be Java on the server. The JNLP is parsed by the client's browser, the required librariers are downloaded and the programm is started, all client-side. The server just provides the files. As for dynamically loading classes through the internet. This should be a lot slower then loading the whole lib, even if there are a few unneeded classes involved. The mix of java and javascript on the client gets me confused. They really cannot interact well with each other. Why do you want to mix those techniques? – Matthias Feb 26 '13 at 06:34
  • Due to user interaction and reusability. It is far more simple than it appears to be. The javascript is the caller and dom manipulator. – marcelo-ferraz Feb 26 '13 at 18:09
  • It appears to be somehow slower in both sides, at first. But it will save those classes to further use, ther is going to be a cache in the server. In lack of this service, downloads jar in the regular fashion. – marcelo-ferraz Feb 26 '13 at 18:15
  • One of the libs that it uses, a proprietary one, has over 1 mega. I rather do it this way than freeze the screen, or make the page wait the whole set of jars to be downloaded. And I learn in the process. – marcelo-ferraz Feb 26 '13 at 18:17