Solved

Help making a JAR archive

Posted on 1998-04-23
17
161 Views
Last Modified: 2013-11-23
I am using a 3rd party product and I need to package my applet in a jar file, but i didn't want to include all the files in the 3r party product in my jar, how can i find out just which files I need and package just those?
0
Comment
Question by:prg022698
  • 9
  • 4
  • 2
  • +2
17 Comments
 
LVL 1

Expert Comment

by:froderik
ID: 1219481
I don't know your general ability with Java but all classes that are used in your program is explicitly mentioned somewhere in your code and typically with import statements at the top of the file. So if your program isn't that big you can read the code to find out.

Another way to do it is to place your own source somewhere isolated from your tool and compile it with JDK. JDK will then produce error messages when it finds classes that are not in the namespace (not in the CLASSPATH). Copy the class files into some directory in your CLASSPATH and recompile.

Hope this helps
0
 

Author Comment

by:prg022698
ID: 1219482
The problem is that the third party party product comes in a jar, with only the bytecode. I wouldn't have a problem if I used only my code of if I had their code.
0
 
LVL 2

Expert Comment

by:jaked
ID: 1219483
OK, this is a pain, but it should work:

Unjar the third party product into a new directory (with 'jar xvf jarfile.jar'). Take the jar out of your CLASSPATH and put the new directory into your CLASSPATH. Recompile just to make sure it worked.

Now try removing (or just renaming) each class file in turn and recompiling your applet. (This could be automated with a shell script.) If you need the class file you just removed, your compile will fail. If the compile succeeds, you can leave the file out. (I guess this is pretty much what frederik said in his second paragraph.) You don't need the third-party source for this process.

This might not work if any of the code loads classes through some other means than mentioning them explicitly (such as Class.forName())--in that case you won't get an error until runtime. Make sure you test the resulting applet for that possibility.
0
 

Author Comment

by:prg022698
ID: 1219484
That won't work either because if a third party class uses another third party class and it is not there I won't get a compile error, because the first class will not be compiled therefore won't be checked. I think I'm right, feel free to correct me if I'm not.
0
 
LVL 1

Expert Comment

by:froderik
ID: 1219485
Some jdk possibilities:
* Run java with the -verbose flag. Then it will print a message to the terminal every time a class is loaded.
* Disassemble the third party classes using javap. Then you can use the one third party class at a time approach indicated above.

There might be tools for finding out dependencies.JBuilder, for example, produces a file with extension ".dependency" in the package folders where the compiler places class files. It is rather hard to read but mentions all dependencies to other classes as well as dependencies to methods in these classes.
0
 

Author Comment

by:prg022698
ID: 1219486
- Run Java with verbose -> must try all the paths so that am sure that all the classes I am able to use are loaded, not doable, what if I miss something?

- Dissassembling and one class at a time is not doable due to the huge amount of classes we are talking about.

- JBuilder is also not an option because it is not available to me

sorry
0
 

Author Comment

by:prg022698
ID: 1219487
- Run Java with verbose -> must try all the paths so that am sure that all the classes I am able to use are loaded, not doable, what if I miss something?

- Dissassembling and one class at a time is not doable due to the huge amount of classes we are talking about.

- JBuilder is also not an option because it is not available to me

sorry
0
 
LVL 1

Expert Comment

by:froderik
ID: 1219488
Then you are stuck. You obviously are looking for an automatic way of doing it and your options then are to either write a tool for it yourself or try to find one that does it for you.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:prg022698
ID: 1219489
Yeap, that is what I was expecting to find out, if there is any tool out there that does it.
Thanks for the input anyway.
0
 
LVL 1

Expert Comment

by:froderik
ID: 1219490
It would not be that hard to write a tool given that you disassemble the third party classes.  Just search the source files for new and record anything after new as a class to depend on. Do it recursively... There is a nice class named java.io.StreamTokenizer that removes comments from the stream. Could be a good tool to have!
0
 

Author Comment

by:prg022698
ID: 1219491
Unfortunately I don't have the time to do it...I'm already behind schedule and need to do some very important stuff. I'll post a comment if I decide to do it and release the code for free.

0
 

Expert Comment

by:mka
ID: 1219492
Hi,

I had a similar problem when my company was launching it's product on the web, and we did not want to use all the 4MB of classses given in the .zip and .jar archives.

We used WinZip to see all the contents of .zip and .jar archives. From it we selected all the packages that we needed. Unzipped/extracted them to the disk. Again, we formed a new .zip or .jar file for the same directory structure but with lot fewer class files - using WinZip. Selecting packages of interest is simple mouse clicks (1 second per selection!). All this procedure will not take more than 30 minutes on Windows 95/NT. For other platforms, you may or may not have such a facility. Using Jar is not very difficult though; and if done on a package by package basis - is not painful. However, for much more custom solution, you'll have to contact me again with more clarification.

Few words of caution would help:
1. Do not go on a class by class basis. It is not right. Go on a package by package basis to see if you have used the package anywhere in your project (to give you and idea, our project had 25 developers and each had written more than 12000 lines of code in java, extensively using these third party classes). The packages you have used are the ones for which you or your co-developers have given an import. If internally it makes reference to another package (these cases being very few), you'll catch them at compilation and add them into the list of packages you'll need.
2. When forming the new .zip or .jar archive file; do take special care to see that you 'save extra directory information'; so that the directory structures for your classes are maintained correctly. Otherwise, WinZip lumps up all the the classes into the .jar file without categorisation or classification.

Write to this topic and I'll be notified by e-mail.

Thanks.
Kaleem (mka).
0
 

Author Comment

by:prg022698
ID: 1219493
I'm not sure I understand what you say, can you mail me at Pedro.Gomes@cp.siemens.pt for more info?
0
 

Expert Comment

by:jreagan
ID: 1219494
First of all, if the third-party has packaged their jar properly, there should be no "unnecessary" classes there.  Just because the classes appear in your code doesn't mean that they don't get used.   If your applet is doing something very basic, then you could do what jaked suggests: unjar and start removing classes.

If download performance is an issue, then don't put your applet in a jar; leave it out, and have your applet download classes behind the scenes.  Unjar your third-party library as well.  This will allow you download classes as they are needed, instead of the whole thing at once.

Bottom line is that you're asking to do something which is against basic OO principals:  worrying about the implementation details of components.
0
 

Author Comment

by:prg022698
ID: 1219495
But I have to jar, because I have to sign it :(

0
 

Accepted Solution

by:
mka earned 150 total points
ID: 1219496
Hi,

Yes, we also had to sign it. So, we had to (yes, had to) 'jar' it. All that I wrote will make sense only if you are working on 95/NT, otherwise you'll have to use your jar options.

For any specific clarification, you can contact me at kaziz@lfrt.com; but still I'd prefer to use these columns for free help.

Thanks.
Kaleem (mka).
0
 

Author Comment

by:prg022698
ID: 1219497
Ok, I'll try it. Thanks for the help all of you provided.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now