Avatar billede di8leva Nybegynder
07. marts 2005 - 10:24 Der er 4 kommentarer og
1 løsning

Building JAR-files using only needed class-files

I am looking for a way to create a JAR-file which includes only the java-files which are used.

For example. I only include the file Foo.class. This file imports com.bar.*, so all classes in com.bar are included, and so on.

Is there anyone who knows a way to do this? Preferrably as an ANT-task.
Avatar billede arne_v Ekspert
07. marts 2005 - 10:32 #1
It is (alomost) impossible.

Because:

import com.bar.*;

does not really include anything - it just means that classname X can be
used at short version for com.bar.X in the source code

But you can still specify com.other.Y without any import in the code.

So you will need to either:
  - analyze the class file with reflection and really see what
    classes are being used
  - analyze the source file as a compiler does and really see what
    classes are being used

Neither are trivial to do.

I am not aware of any tool dedicated to do this.

But most obfuscators can actually do this: remove unused code.

Try look at f.ex. ProGuard.
Avatar billede vandspand Nybegynder
07. marts 2005 - 10:32 #2
dont know other ways than to find and put them together manually and then make a .jar file with the jar-maker-thingy...

Thats what I've done
Avatar billede di8leva Nybegynder
07. marts 2005 - 10:37 #3
It seems that ProGuard is almost what we are looking for. I meant that I was looking for a tool to remove unused code, and since ProGuard also comes with a plugin for ANT, it's seems perfect.

Thanks
Avatar billede di8leva Nybegynder
07. marts 2005 - 10:38 #4
arne_v >> smider du et svar?
Avatar billede arne_v Ekspert
07. marts 2005 - 10:42 #5
kommer her
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester