2010-02-18 49 views
3

我有一個1MB的.jar文件。沒有調試信息,它應該是大約100KB。現在,我如何去除調試信息?Java jar符號信息:什麼是tdstrip的等價物?

borland世界的老朋友可能會記得一個名爲tdstrip的工具,它可以從.exe中刪除符號信息。

Java世界中的等價物是什麼?我試圖做一個1MB文件太大的移動開發。

我知道我可以在沒有調試信息的情況下重新編譯和重建.jar文件,但是如果您沒有源代碼等,那麼您如何去做呢?

+0

並移除調試符號真的在罐子尺寸如此巨大的影響? – Thilo 2010-02-18 09:51:10

+0

恩,是... http://java.sun.com/docs/books/performance/1st_edition/html/JPDeployment.fm.html – 2011-02-23 00:09:06

回答

1

在移動世界中部署時,通過一些混淆工具運行整個jar文件是很常見的。

這樣做的主要用途並不是使反編譯更難,而是大大減小jar的大小。

混淆工具已經實現了減少你罐子的大小許多步驟:

  • 縮短所有存儲的標識符,以儘可能少的
  • 剝離所有調試信息和非基本屬性
  • 甚至可能重寫字節碼以使用更少的空間
4

使用%JAVA_HOME%/bin/pack200 -r -G jartostrip.jar

Usage: pack200 [-opt... | --option=value]... x.pack[.gz] y.jar 

Packing Options 
    -g, --no-gzip     output a plain *.pack file with no zipping 
    --gzip       (default) post-process the pack output with gzip 
    -G, --strip-debug    remove debugging attributes while packing 
    -O, --no-keep-file-order  do not transmit file ordering information 
    --keep-file-order    (default) preserve input file ordering 
    -S{N}, --segment-limit={N}  output segment limit (default N=1Mb) 
    -E{N}, --effort={N}    packing effort (default N=5) 
    -H{h}, --deflate-hint={h}  transmit deflate hint: true, false, or keep (default) 
    -m{V}, --modification-time={V} transmit modtimes: latest or keep (default) 
    -P{F}, --pass-file={F}   transmit the given input element(s) uncompressed 
    -U{a}, --unknown-attribute={a} unknown attribute action: error, strip, or pass (default) 
    -C{N}={L}, --class-attribute={N}={L} (user-defined attribute) 
    -F{N}={L}, --field-attribute={N}={L} (user-defined attribute) 
    -M{N}={L}, --method-attribute={N}={L} (user-defined attribute) 
    -D{N}={L}, --code-attribute={N}={L} (user-defined attribute) 
    -f{F}, --config-file={F}  read file F for Pack200.Packer properties 
    -v, --verbose     increase program verbosity 
    -q, --quiet      set verbosity to lowest level 
    -l{F}, --log-file={F}   output to the given log file, or '-' for System.out 
    -?, -h, --help     print this message 
    -V, --version     print program version 
    -J{X}       pass option X to underlying Java VM 

Notes: 
    The -P, -C, -F, -M, and -D options accumulate. 
    Example attribute definition: -C SourceFile=RUH . 
    Config. file properties are defined by the Pack200 API. 
    For meaning of -S, -E, -H-, -m, -U values, see Pack200 API. 
    Layout definitions (like RUH) are defined by JSR 200. 

Repacking mode updates the JAR file with a pack/unpack cycle: 
    pack200 [-r|--repack] [-opt | --option=value]... [repackedy.jar] y.jar 
+0

實際上,這樣做的話從1,082,391增加到1,094,056字節! – anjanb 2010-02-19 06:06:44

+0

好奇,你看了之前和之後的瓶子之間的區別? – PSpeed 2010-02-19 07:30:25

+0

在我的測試中,文件大小減少了20%,也許你的oringal文件被壓縮得更高(-E選項),試圖壓縮更多agressivly。另請參閱:http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/pack200.html – stacker 2010-02-19 09:40:16

相關問題