1 <!doctype html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 2 <html> 3 <head> 4 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> 5 <meta http-equiv="content-style-type" content="text/css"> 6 <link rel="stylesheet" type="text/css" href="style.css"> 7 <title>ProGuard Examples</title> 8 </head> 9 <body> 10 11 <h2>Examples</h2> 12 13 Some typical useful configurations: 14 <ol> 15 <li><a href="#application">A typical application</a> 16 <li><a href="#applet">A typical applet</a> 17 <li><a href="#midlet">A typical midlet</a> 18 <li><a href="#jcapplet">A typical Java Card applet</a> 19 <li><a href="#xlet">A typical xlet</a> 20 <li><a href="#androidapplication">A typical Android application</a> 21 <li><a href="#library">A typical library</a> 22 <li><a href="#applications">All possible applications in the input jars</a> 23 <li><a href="#applets">All possible applets in the input jars</a> 24 <li><a href="#midlets">All possible midlets in the input jars</a> 25 <li><a href="#jcapplets">All possible Java Card applets in the input jars</a> 26 <li><a href="#xlets">All possible xlets in the input jars</a> 27 <li><a href="#androidapplications">All possible Android applications in the input jars</a> 28 <li><a href="#servlets">All possible servlets in the input jars</a> 29 <li><a href="#native">Processing native methods</a> 30 <li><a href="#callback">Processing callback methods</a> 31 <li><a href="#enumerations">Processing enumeration classes</a> 32 <li><a href="#serializable">Processing serializable classes</a> 33 <li><a href="#beans">Processing bean classes</a> 34 <li><a href="#annotations">Processing annotations</a> 35 <li><a href="#database">Processing database drivers</a> 36 <li><a href="#componentui">Processing ComponentUI classes</a> 37 <li><a href="#rmi">Processing RMI code</a> 38 <li><a href="#resourcefiles">Processing resource files</a> 39 <li><a href="#stacktrace">Producing useful obfuscated stack traces</a> 40 <li><a href="#repackaging">Obfuscating package names</a> 41 <li><a href="#restructuring">Restructuring the output archives</a> 42 <li><a href="#filtering">Filtering the input and the output</a> 43 <li><a href="#multiple">Processing multiple applications at once</a> 44 <li><a href="#incremental">Incremental obfuscation</a> 45 <li><a href="#microedition">Preverifying class files for Java Micro Edition</a> 46 <li><a href="#upgrade">Upgrading class files to Java 6</a> 47 <li><a href="#deadcode">Finding dead code</a> 48 <li><a href="#structure">Printing out the internal structure of class files</a> 49 <li><a href="#annotated">Using annotations to configure ProGuard</a> 50 </ol> 51 52 You can find some sample configuration files in the <code>examples</code> 53 directory of the ProGuard distribution. 54 55 <a name="application"> </a> 56 <h3>A typical application</h3> 57 To shrink, optimize, and obfuscate the ProGuard application itself, one would 58 typically create a configuration file <code>proguard.pro</code> and then type: 59 <pre> 60 java -jar proguard.jar @proguard.pro 61 </pre> 62 <p> 63 The configuration file would contain the following options: 64 <pre> 65 -injars proguard.jar 66 -outjars proguard_out.jar 67 -libraryjars <java.home>/lib/rt.jar 68 -printmapping proguard.map 69 70 -keep public class proguard.ProGuard { 71 public static void main(java.lang.String[]); 72 } 73 </pre> 74 <p> 75 Note the use of the <code><java.home></code> system property; it is 76 replaced automatically. 77 <p> 78 Also note that all type names are fully specified: 79 <code>proguard.ProGuard</code> and <code>java.lang.String[]</code>. 80 <p> 81 The access modifiers <code>public</code> and <code>static</code> are not 82 really required in this case, since we know a priori that the specified class 83 and method have the proper access flags. It just looks more familiar this way. 84 <p> 85 We're writing out an obfuscation mapping file with <a 86 href="usage.html#printmapping"><code>-printmapping</code></a>, for 87 de-obfuscating any stack traces later on, or for incremental obfuscation of 88 extensions. 89 <p> 90 We can further improve the results with a few additional options: 91 <pre> 92 -optimizationpasses 3 93 -overloadaggressively 94 -repackageclasses '' 95 -allowaccessmodification 96 </pre> 97 These options are not required; they just shave off some extra bytes from the 98 output jar, by performing up to 3 optimization passes, and by aggressively 99 obfuscating class members and <a href="#repackaging">package names</a>. 100 <p> 101 In general, you might need a few additional options for processing <a 102 href="#native">native methods</a>, <a href="#callback">callback methods</a>, 103 <a href="#enumerations">enumerations</a>, <a href="#serializable">serializable 104 classes</a>, <a href="#beans">bean classes</a>, <a 105 href="#annotations">annotations</a>, and <a href="#resourcefiles">resource 106 files</a>. For processing 'simple' applications like ProGuard, that is not 107 required. 108 109 <a name="applet"> </a> 110 <h3>A typical applet</h3> 111 These options shrink, optimize, and obfuscate the applet 112 <code>mypackage.MyApplet</code>: 113 <pre> 114 -injars in.jar 115 -outjars out.jar 116 -libraryjars <java.home>/lib/rt.jar 117 118 -keep public class mypackage.MyApplet 119 </pre> 120 <p> 121 The typical applet methods will be preserved automatically, since 122 <code>mypackage.MyApplet</code> is an extension of the <code>Applet</code> 123 class in the library <code>rt.jar</code>. 124 <p> 125 If applicable, you should add options for processing <a href="#native">native 126 methods</a>, <a href="#callback">callback methods</a>, <a 127 href="#enumerations">enumerations</a>, <a href="#serializable">serializable 128 classes</a>, <a href="#beans">bean classes</a>, <a 129 href="#annotations">annotations</a>, and <a href="#resourcefiles">resource 130 files</a>. 131 132 <a name="midlet"> </a> 133 <h3>A typical midlet</h3> 134 These options shrink, optimize, obfuscate, and preverify the midlet 135 <code>mypackage.MyMIDlet</code>: 136 <pre> 137 -injars in.jar 138 -outjars out.jar 139 -libraryjars /usr/local/java/wtk2.1/lib/midpapi20.jar 140 -libraryjars /usr/local/java/wtk2.1/lib/cldcapi11.jar 141 -overloadaggressively 142 -repackageclasses '' 143 -allowaccessmodification 144 -microedition 145 146 -keep public class mypackage.MyMIDlet 147 </pre> 148 <p> 149 Note how we're now targeting the Java Micro Edition run-time environment of 150 <code>midpapi20.jar</code> and <code>cldcapi11.jar</code>, instead of the Java 151 Standard Edition run-time environment <code>rt.jar</code>. You can target 152 other JME environments by picking the appropriate jars. 153 <p> 154 The typical midlet methods will be preserved automatically, since 155 <code>mypackage.MyMIDlet</code> is an extension of the <code>MIDlet</code> 156 class in the library <code>midpapi20.jar</code>. 157 <p> 158 The <a href="usage.html#microedition"><code>-microedition</code></a> option 159 makes sure the class files are preverified for Java Micro Edition, producing 160 compact <code>StackMap</code> attributes. It is no longer necessary to run an 161 external preverifier. 162 <p> 163 Be careful if you do use the external <code>preverify</code> tool on a platform 164 with a case-insensitive filing system, such as Windows. Because this tool 165 unpacks your processed jars, you should then use ProGuard's <a 166 href="usage.html#dontusemixedcaseclassnames"><code>-dontusemixedcaseclassnames</code></a> 167 option. 168 <p> 169 If applicable, you should add options for processing <a href="#native">native 170 methods</a> and <a href="#resourcefiles">resource files</a>. 171 <p> 172 Note that you will still have to adapt the midlet jar size in the 173 corresponding jad file; ProGuard doesn't do that for you. 174 175 <a name="jcapplet"> </a> 176 <h3>A typical Java Card applet</h3> 177 These options shrink, optimize, and obfuscate the Java Card applet 178 <code>mypackage.MyApplet</code>: 179 <pre> 180 -injars in.jar 181 -outjars out.jar 182 -libraryjars /usr/local/java/javacard2.2.2/lib/api.jar 183 -dontwarn java.lang.Class 184 -overloadaggressively 185 -repackageclasses '' 186 -allowaccessmodification 187 188 -keep public class mypackage.MyApplet 189 </pre> 190 <p> 191 The configuration is very similar to the configuration for midlets, except that 192 it now targets the Java Card run-time environment. This environment doesn't 193 have java.lang.Class, so we're telling ProGuard not to worry about it. 194 195 <a name="xlet"> </a> 196 <h3>A typical xlet</h3> 197 These options shrink, optimize, and obfuscate the xlet 198 <code>mypackage.MyXlet</code>: 199 <pre> 200 -injars in.jar 201 -outjars out.jar 202 -libraryjars /usr/local/java/jtv1.1/javatv.jar 203 -libraryjars /usr/local/java/cdc1.1/lib/cdc.jar 204 -libraryjars /usr/local/java/cdc1.1/lib/btclasses.zip 205 -overloadaggressively 206 -repackageclasses '' 207 -allowaccessmodification 208 209 -keep public class mypackage.MyXlet 210 </pre> 211 <p> 212 The configuration is very similar to the configuration for midlets, except that 213 it now targets the CDC run-time environment with the Java TV API. 214 215 <a name="androidapplication"> </a> 216 <h3>A typical Android application</h3> 217 These options shrink, optimize, and obfuscate the simple Android application 218 based on a single activity <code>mypackage.MyActivity</code>: 219 <pre> 220 -injars in.jar 221 -outjars out.jar 222 -libraryjars /usr/local/java/android-1.5_r1/platforms/android-1.5/android.jar 223 -overloadaggressively 224 -repackageclasses '' 225 -allowaccessmodification 226 -optimizations !code/simplification/arithmetic 227 228 -keep public class mypackage.MyActivity 229 </pre> 230 <p> 231 The configuration is very similar to the configuration for midlets, except that 232 it now targets the Android run-time environment. 233 <p> 234 The <a href="usage.html#optimizations"><code>-optimizations</code></a> option 235 disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. 236 <p> 237 If applicable, you should add options for processing <a href="#native">native 238 methods</a>, <a href="#callback">callback methods</a>, and <a 239 href="#resourcefiles">resource files</a>. 240 241 <a name="library"> </a> 242 <h3>A typical library</h3> 243 These options shrink, optimize, and obfuscate an entire library, keeping all 244 public and protected classes and class members, native method names, and 245 serialization code: 246 <pre> 247 -injars in.jar 248 -outjars out.jar 249 -libraryjars <java.home>/lib/rt.jar 250 -printmapping out.map 251 252 -renamesourcefileattribute SourceFile 253 -keepattributes Exceptions,InnerClasses,Signature,Deprecated, 254 SourceFile,LineNumberTable,*Annotation*,EnclosingMethod 255 256 -keep public class * { 257 public protected *; 258 } 259 260 -keepclassmembernames class * { 261 java.lang.Class class$(java.lang.String); 262 java.lang.Class class$(java.lang.String, boolean); 263 } 264 265 -keepclasseswithmembernames class * { 266 native <methods>; 267 } 268 269 -keepclassmembers enum * { 270 public static **[] values(); 271 public static ** valueOf(java.lang.String); 272 } 273 274 -keepclassmembers class * implements java.io.Serializable { 275 static final long serialVersionUID; 276 private void writeObject(java.io.ObjectOutputStream); 277 private void readObject(java.io.ObjectInputStream); 278 java.lang.Object writeReplace(); 279 java.lang.Object readResolve(); 280 } 281 </pre> 282 <p> 283 This configuration should preserve everything we'll ever want to access in the 284 library. Only if there are any other non-public classes or methods that are 285 invoked dynamically, they should be specified using additional <a 286 href="usage.html#keep"><code>-keep</code></a> options. 287 <p> 288 The <a 289 href="usage.html#keepclassmembernames"><code>-keepclassmembernames</code></a> 290 option for the <code>class$</code> methods is not strictly necessary. These 291 methods are inserted by the <code>javac</code> compiler and the 292 <code>jikes</code> compiler respectively, to implement the <code>.class</code> 293 construct. ProGuard will automatically detect them and deal with them, even 294 when their names have been obfuscated. However, older versions of ProGuard and 295 other obfuscators may rely on the original method names. It may therefore be 296 helpful to preserve them, in case these other obfuscators are ever used for 297 further obfuscation of the library. 298 <p> 299 The "Exceptions" attribute has to be preserved, so the compiler knows which 300 exceptions methods may throw. 301 <p> 302 The "InnerClasses" attribute (or more precisely, its source name part) has to 303 be preserved too, for any inner classes that can be referenced from outside the 304 library. The <code>javac</code> compiler would be unable to find the inner 305 classes otherwise. 306 <p> 307 The "Signature" attribute is required to be able to access generic types when 308 compiling in JDK 5.0 and higher. 309 <p> 310 Finally, we're keeping the "Deprecated" attribute and the attributes for 311 producing <a href="#stacktrace">useful stack traces</a>. 312 <p> 313 We've also added some options for for processing <a href="#native">native 314 methods</a>, <a href="#enumerations">enumerations</a>, <a 315 href="#serializable">serializable classes</a>, and <a 316 href="#annotations">annotations</a>, which are all discussed in their 317 respective examples. 318 319 <a name="applications"> </a> 320 <h3>All possible applications in the input jars</h3> 321 These options shrink, optimize, and obfuscate all public applications in 322 <code>in.jar</code>: 323 <pre> 324 -injars in.jar 325 -outjars out.jar 326 -libraryjars <java.home>/lib/rt.jar 327 -printseeds 328 329 -keepclasseswithmembers public class * { 330 public static void main(java.lang.String[]); 331 } 332 </pre> 333 <p> 334 Note the use of <a 335 href="usage.html#keepclasseswithmembers"><code>-keepclasseswithmembers</code></a>. 336 We don't want to preserve all classes, just all classes that have main 337 methods, and those methods. 338 <p> 339 The <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 340 out which classes exactly will be preserved, so we know for sure we're getting 341 what we want. 342 <p> 343 If applicable, you should add options for processing <a href="#native">native 344 methods</a>, <a href="#callback">callback methods</a>, <a 345 href="#enumerations">enumerations</a>, <a href="#serializable">serializable 346 classes</a>, <a href="#beans">bean classes</a>, <a 347 href="#annotations">annotations</a>, and <a href="#resourcefiles">resource 348 files</a>. 349 350 <a name="applets"> </a> 351 <h3>All possible applets in the input jars</h3> 352 These options shrink, optimize, and obfuscate all public applets in 353 <code>in.jar</code>: 354 <pre> 355 -injars in.jar 356 -outjars out.jar 357 -libraryjars <java.home>/lib/rt.jar 358 -printseeds 359 360 -keep public class * extends java.applet.Applet 361 </pre> 362 <p> 363 We're simply keeping all classes that extend the <code>Applet</code> class. 364 <p> 365 Again, the <a href="usage.html#printseeds"><code>-printseeds</code></a> option 366 prints out which applets exactly will be preserved. 367 <p> 368 If applicable, you should add options for processing <a href="#native">native 369 methods</a>, <a href="#callback">callback methods</a>, <a 370 href="#enumerations">enumerations</a>, <a href="#serializable">serializable 371 classes</a>, <a href="#beans">bean classes</a>, <a 372 href="#annotations">annotations</a>, and <a href="#resourcefiles">resource 373 files</a>. 374 375 <a name="midlets"> </a> 376 <h3>All possible midlets in the input jars</h3> 377 These options shrink, optimize, obfuscate, and preverify all public midlets in 378 <code>in.jar</code>: 379 <pre> 380 -injars in.jar 381 -outjars out.jar 382 -libraryjars /usr/local/java/wtk2.1/lib/midpapi20.jar 383 -libraryjars /usr/local/java/wtk2.1/lib/cldcapi11.jar 384 -overloadaggressively 385 -repackageclasses '' 386 -allowaccessmodification 387 -microedition 388 -printseeds 389 390 -keep public class * extends javax.microedition.midlet.MIDlet 391 </pre> 392 <p> 393 We're simply keeping all classes that extend the <code>MIDlet</code> class. 394 <p> 395 The <a href="usage.html#microedition"><code>-microedition</code></a> option 396 makes sure the class files are preverified for Java Micro Edition, producing 397 compact <code>StackMap</code> attributes. It is no longer necessary to run an 398 external preverifier. 399 <p> 400 Be careful if you do use the external <code>preverify</code> tool on a platform 401 with a case-insensitive filing system, such as Windows. Because this tool 402 unpacks your processed jars, you should then use ProGuard's <a 403 href="usage.html#dontusemixedcaseclassnames"><code>-dontusemixedcaseclassnames</code></a> 404 option. 405 <p> 406 The <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 407 out which midlets exactly will be preserved. 408 <p> 409 If applicable, you should add options for processing <a href="#native">native 410 methods</a> and <a href="#resourcefiles">resource files</a>. 411 <p> 412 Note that you will still have to adapt the midlet jar size in the 413 corresponding jad file; ProGuard doesn't do that for you. 414 415 <a name="jcapplets"> </a> 416 <h3>All possible Java Card applets in the input jars</h3> 417 These options shrink, optimize, and obfuscate all public Java Card applets in 418 <code>in.jar</code>: 419 <pre> 420 -injars in.jar 421 -outjars out.jar 422 -libraryjars /usr/local/java/javacard2.2.2/lib/api.jar 423 -dontwarn java.lang.Class 424 -overloadaggressively 425 -repackageclasses '' 426 -allowaccessmodification 427 -printseeds 428 429 -keep public class * implements javacard.framework.Applet 430 </pre> 431 <p> 432 We're simply keeping all classes that implement the <code>Applet</code> 433 interface. 434 <p> 435 The <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 436 out which applets exactly will be preserved. 437 438 <a name="xlets"> </a> 439 <h3>All possible xlets in the input jars</h3> 440 These options shrink, optimize, and obfuscate all public xlets in 441 <code>in.jar</code>: 442 <pre> 443 -injars in.jar 444 -outjars out.jar 445 -libraryjars /usr/local/java/jtv1.1/javatv.jar 446 -libraryjars /usr/local/java/cdc1.1/lib/cdc.jar 447 -libraryjars /usr/local/java/cdc1.1/lib/btclasses.zip 448 -overloadaggressively 449 -repackageclasses '' 450 -allowaccessmodification 451 -printseeds 452 453 -keep public class * implements javax.tv.xlet.Xlet 454 </pre> 455 <p> 456 We're simply keeping all classes that implement the <code>Xlet</code> interface. 457 <p> 458 The <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 459 out which xlets exactly will be preserved. 460 461 <a name="androidapplications"> </a> 462 <h3>All possible Android applications in the input jars</h3> 463 These options shrink, optimize, and obfuscate all public activities, services, 464 broadcast receivers, and content providers in <code>in.jar</code>: 465 <pre> 466 -injars in.jar 467 -outjars out.jar 468 -libraryjars /usr/local/java/android-1.5_r1/platforms/android-1.5/android.jar 469 -overloadaggressively 470 -repackageclasses '' 471 -allowaccessmodification 472 -optimizations !code/simplification/arithmetic 473 -printseeds 474 475 -keep public class * extends android.app.Activity 476 -keep public class * extends android.app.Service 477 -keep public class * extends android.content.BroadcastReceiver 478 -keep public class * extends android.content.ContentProvider 479 </pre> 480 <p> 481 We're keeping all classes that extend the base classes that may be referenced 482 by the <code>AndroidManifest.xml</code> file of the application. 483 <p> 484 The <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 485 out which implementations exactly will be preserved. 486 <p> 487 If applicable, you should add options for processing <a href="#native">native 488 methods</a>, <a href="#callback">callback methods</a>, and <a 489 href="#resourcefiles">resource files</a>. 490 491 <a name="servlets"> </a> 492 <h3>All possible servlets in the input jars</h3> 493 These options shrink, optimize, and obfuscate all public servlets in 494 <code>in.jar</code>: 495 <pre> 496 -injars in.jar 497 -outjars out.jar 498 -libraryjars <java.home>/lib/rt.jar 499 -libraryjars /usr/local/java/servlet/servlet.jar 500 -printseeds 501 502 -keep public class * implements javax.servlet.Servlet 503 </pre> 504 <p> 505 Keeping all servlets is very similar to keeping all applets. The servlet API 506 is not part of the standard run-time jar, so we're specifying it as a library. 507 Don't forget to use the right path name. 508 <p> 509 We're then keeping all classes that implement the <code>Servlet</code> 510 interface. We're using the <code>implements</code> keyword because it looks 511 more familiar in this context, but it is equivalent to <code>extends</code>, 512 as far as ProGuard is concerned. 513 <p> 514 The <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 515 out which servlets exactly will be preserved. 516 <p> 517 If applicable, you should add options for processing <a href="#native">native 518 methods</a>, <a href="#callback">callback methods</a>, <a 519 href="#enumerations">enumerations</a>, <a href="#serializable">serializable 520 classes</a>, <a href="#beans">bean classes</a>, <a 521 href="#annotations">annotations</a>, and <a href="#resourcefiles">resource 522 files</a>. 523 524 <a name="native"> </a> 525 <h3>Processing native methods</h3> 526 If your application, applet, servlet, library, etc., contains native methods, 527 you'll want to preserve their names and their classes' names, so they can 528 still be linked to the native library. The following additional option will 529 ensure that: 530 <pre> 531 -keepclasseswithmembernames class * { 532 native <methods>; 533 } 534 </pre> 535 <p> 536 Note the use of <a 537 href="usage.html#keepclasseswithmembernames"><code>-keepclasseswithmembernames</code></a>. 538 We don't want to preserve all classes or all native methods; we just want to 539 keep the relevant names from being obfuscated. 540 <p> 541 ProGuard doesn't look at your native code, so it won't automatically preserve 542 the classes or class members that are invoked by the native code. These are 543 entry points, which you'll have to specify explicitly. <a 544 href="callback">Callback methods</a> are discussed below as a typical example. 545 546 <a name="callback"> </a> 547 <h3>Processing callback methods</h3> 548 If your application, applet, servlet, library, etc., contains callback 549 methods, which are called from external code (native code, scripts,...), 550 you'll want to preserve them, and probably their classes too. They are just 551 entry points to your code, much like, say, the main method of an application. 552 If they aren't preserved by other <code>-keep</code> options, something like 553 the following option will keep the callback class and method: 554 <pre> 555 -keep class mypackage.MyCallbackClass { 556 void myCallbackMethod(java.lang.String); 557 } 558 </pre> 559 <p> 560 This will preserve the given class and method from being removed or renamed. 561 562 <a name="enumerations"> </a> 563 <h3>Processing enumeration classes</h3> 564 If your application, applet, servlet, library, etc., contains enumeration 565 classes, you'll have to preserve some special methods. Enumerations were 566 introduced in Java 5. The java compiler translates enumerations into classes 567 with a special structure. Notably, the classes contain implementations of some 568 static methods that the run-time environment accesses by introspection (Isn't 569 that just grand? Introspection is the self-modifying code of a new 570 generation). You have to specify these explicitly, to make sure they aren't 571 removed or obfuscated: 572 <pre> 573 -keepclassmembers enum * { 574 public static **[] values(); 575 public static ** valueOf(java.lang.String); 576 } 577 </pre> 578 579 <a name="serializable"> </a> 580 <h3>Processing serializable classes</h3> 581 More complex applications, applets, servlets, libraries, etc., may contain 582 classes that are serialized. Depending on the way in which they are used, they 583 may require special attention: 584 <ul> 585 586 <li>Often, serialization is simply a means of transporting data, without 587 long-term storage. Classes that are shrunk and obfuscated should then 588 continue to function fine with the following additional options: 589 590 <pre> 591 -keepclassmembers class * implements java.io.Serializable { 592 private void writeObject(java.io.ObjectOutputStream); 593 private void readObject(java.io.ObjectInputStream); 594 java.lang.Object writeReplace(); 595 java.lang.Object readResolve(); 596 } 597 </pre> 598 <p> 599 600 The <a 601 href="usage.html#keepclassmembers"><code>-keepclassmembers</code></a> 602 option makes sure that any serialization methods are kept. By using this 603 option instead of the basic <code>-keep</code> option, we're not 604 forcing preservation of <i>all</i> serializable classes, just preservation 605 of the listed members of classes that are actually used. 606 <p> 607 608 <li>Sometimes, the serialized data are stored, and read back later into newer 609 versions of the serializable classes. One then has to take care the classes 610 remain compatible with their unprocessed versions and with future 611 processed versions. In such cases, the relevant classes will most likely 612 have <code>serialVersionUID</code> fields. The following options should 613 then be sufficient to ensure compatibility over time: 614 615 <pre> 616 -keepnames class * implements java.io.Serializable 617 618 -keepclassmembers class * implements java.io.Serializable { 619 static final long serialVersionUID; 620 static final java.io.ObjectStreamField[] serialPersistentFields; 621 !static !transient <fields>; 622 private void writeObject(java.io.ObjectOutputStream); 623 private void readObject(java.io.ObjectInputStream); 624 java.lang.Object writeReplace(); 625 java.lang.Object readResolve(); 626 } 627 </pre> 628 <p> 629 630 The <code>serialVersionUID</code> and <code>serialPersistentFields</code> 631 lines makes sure those fields are preserved, if they are present. 632 The <code><fields></code> line preserves all non-static, 633 non-transient fields, with their original names. The introspection of the 634 serialization process and the de-serialization process will then find 635 consistent names. 636 637 <li>Occasionally, the serialized data have to remain compatible, but the 638 classes involved lack <code>serialVersionUID</code> fields. I imagine the 639 original code will then be hard to maintain, since the serial version UID 640 is then computed from a list of features the serializable class. Changing 641 the class ever so slightly may change the computed serial version UID. The 642 list of features is specified in the section on <a 643 href="http://java.sun.com/javase/6/docs/platform/serialization/spec/class.html#4100">Stream 644 Unique Identifiers</a> of Sun's <a 645 href="http://java.sun.com/javase/6/docs/platform/serialization/spec/serialTOC.html">Java 646 Object Serialization Specification</a>. The following directives should at 647 least partially ensure compatibility with the original classes: 648 649 <pre> 650 -keepnames class * implements java.io.Serializable 651 652 -keepclassmembers class * implements java.io.Serializable { 653 static final long serialVersionUID; 654 static final java.io.ObjectStreamField[] serialPersistentFields; 655 !static !transient <fields>; 656 !private <fields>; 657 !private <methods>; 658 private void writeObject(java.io.ObjectOutputStream); 659 private void readObject(java.io.ObjectInputStream); 660 java.lang.Object writeReplace(); 661 java.lang.Object readResolve(); 662 } 663 </pre> 664 <p> 665 666 The new options force preservation of the elements involved in the UID 667 computation. In addition, the user will have to manually specify all 668 interfaces of the serializable classes (using something like "<code>-keep 669 interface MyInterface</code>"), since these names are also used when 670 computing the UID. A fast but sub-optimal alternative would be simply 671 keeping all interfaces with "<code>-keep interface *</code>". 672 673 </ul> 674 <p> 675 676 Note that the above options may preserve more classes and class members 677 than strictly necessary. For instance, a large number of classes may implement 678 the <code>Serialization</code> interface, yet only a small number may actually 679 ever be serialized. Knowing your application and tuning the configuration 680 often produces more compact results. 681 682 <a name="beans"> </a> 683 <h3>Processing bean classes</h3> 684 If your application, applet, servlet, library, etc., makes extensive use of 685 introspection on bean classes to find bean editor classes, or getter and 686 setter methods, then configuration may become painful. There's not much else 687 you can do than making sure the bean class names, or the getter and setter 688 names don't change. For instance: 689 <pre> 690 -keep public class mypackage.MyBean { 691 public void setMyProperty(int); 692 public int getMyProperty(); 693 } 694 695 -keep public class mypackage.MyBeanEditor 696 </pre> 697 <p> 698 If there are too many elements to list explicitly, wildcards in class names 699 and method signatures might be helpful. This example should encompasses all 700 possible setters and getters in classes in the package <code>mybeans</code>: 701 <pre> 702 -keep class mybeans.** { 703 void set*(***); 704 void set*(int, ***); 705 706 boolean is*(); 707 boolean is*(int); 708 709 *** get*(); 710 *** get*(int); 711 } 712 </pre> 713 <p> 714 The '<code>***</code>' wildcard matches any type (primitive or non-primitive, 715 array or non-array). The methods with the '<code>int</code>' arguments matches 716 properties that are lists. 717 718 <a name="annotations"> </a> 719 <h3>Processing annotations</h3> 720 If your application, applet, servlet, library, etc., uses annotations, you may 721 want to preserve them in the processed output. Annotations are represented by 722 attributes that have no direct effect on the execution of the code. However, 723 their values can be retrieved through introspection, allowing developers to 724 adapt the execution behavior accordingly. By default, ProGuard treats 725 annotation attributes as optional, and removes them in the obfuscation step. 726 If they are required, you'll have to specify this explicitly: 727 <pre> 728 -keepattributes *Annotation* 729 </pre> 730 <p> 731 For brevity, we're specifying a wildcarded attribute name, which will match 732 <code>RuntimeVisibleAnnotations</code>, 733 <code>RuntimeInvisibleAnnotations</code>, 734 <code>RuntimeVisibleParameterAnnotations</code>, 735 <code>RuntimeInvisibleParameterAnnotations</code>, and 736 <code>AnnotationDefault</code>. Depending on the purpose of the processed 737 code, you could refine this selection, for instance not keeping the run-time 738 invisible annotations (which are only used at compile-time). 739 <p> 740 Some code may make further use of introspection to figure out the enclosing 741 methods of anonymous inner classes. In that case, the corresponding attribute 742 has to be preserved as well: 743 <pre> 744 -keepattributes EnclosingMethod 745 </pre> 746 747 <a name="database"> </a> 748 <h3>Processing database drivers</h3> 749 Database drivers are implementations of the <code>Driver</code> interface. 750 Since they are often created dynamically, you may want to preserve any 751 implementations that you are processing as entry points: 752 <pre> 753 -keep class * implements java.sql.Driver 754 </pre> 755 <p> 756 This option also gets rid of the note that ProGuard prints out about 757 <code>(java.sql.Driver)Class.forName</code> constructs, if you are 758 instantiating a driver in your code (without necessarily implementing any 759 drivers yourself). 760 761 <a name="componentui"> </a> 762 <h3>Processing ComponentUI classes</h3> 763 Swing UI look and feels are implemented as extensions of the 764 <code>ComponentUI</code> class. For some reason, these have to contain a 765 static method <code>createUI</code>, which the Swing API invokes using 766 introspection. You should therefore always preserve the method as an entry 767 point, for instance like this: 768 <pre> 769 -keep class * extends javax.swing.plaf.ComponentUI { 770 public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent); 771 } 772 </pre> 773 <p> 774 This option also keeps the classes themselves. 775 776 <a name="rmi"> </a> 777 <h3>Processing RMI code</h3> 778 Reportedly, the easiest way to handle RMI code is to process the code with 779 ProGuard first and then invoke the <code>rmic</code> tool. If that is not 780 possible, you may want to try something like this: 781 <pre> 782 -keepattributes Exceptions 783 784 -keep interface * extends java.rmi.Remote { 785 <methods>; 786 } 787 788 -keep class * implements java.rmi.Remote { 789 <init>(java.rmi.activation.ActivationID, java.rmi.MarshalledObject); 790 } 791 </pre> 792 <p> 793 The first <code>-keep</code> option keeps all your Remote interfaces and their 794 methods. The second one keeps all the implementations, along with their 795 particular RMI constructors, if any. 796 <p> 797 The <code>Exceptions</code> attribute has to be kept too, because the RMI 798 handling code performs introspection to check whether the method signatures 799 are compatible. 800 801 <a name="resourcefiles"> </a> 802 <h3>Processing resource files</h3> 803 If your application, applet, servlet, library, etc., contains resource files, 804 it may be necessary to adapt their names and/or their contents when the 805 application is obfuscated. The following two options can achieve this 806 automatically: 807 <pre> 808 -adaptresourcefilenames **.properties,**.gif,**.jpg 809 -adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF 810 </pre> 811 <p> 812 The <a href="usage.html#adaptresourcefilenames">-adaptresourcefilenames</a> 813 option in this case renames properties files and image files in the processed 814 output, based on the obfuscated names of their corresponding class files (if 815 any). The <a 816 href="usage.html#adaptresourcefilecontents">-adaptresourcefilecontents</a> 817 option looks for class names in properties files and in the manifest file, and 818 replaces these names by the obfuscated names (if any). You'll probably want to 819 adapt the filters to suit your application. 820 821 <a name="stacktrace"> </a> 822 <h3>Producing useful obfuscated stack traces</h3> 823 These options let obfuscated applications or libraries produce stack traces 824 that can still be deciphered later on: 825 <pre> 826 -printmapping out.map 827 828 -renamesourcefileattribute SourceFile 829 -keepattributes SourceFile,LineNumberTable 830 </pre> 831 <p> 832 We're keeping all source file attributes, but we're replacing their values by 833 the string "SourceFile". We could use any string. This string is already 834 present in all class files, so it doesn't take up any extra space. If you're 835 working with J++, you'll want to keep the "SourceDir" attribute as well. 836 <p> 837 We're also keeping the line number tables of all methods. 838 <p> 839 Whenever both of these attributes are present, the Java run-time environment 840 will include line number information when printing out exception stack traces. 841 <p> 842 The information will only be useful if we can map the obfuscated names back to 843 their original names, so we're saving the mapping to a file 844 <code>out.map</code>. The information can then be used by the <a 845 href="retrace/index.html">ReTrace</a> tool to restore the original stack trace. 846 847 <a name="repackaging"> </a> 848 <h3>Obfuscating package names</h3> 849 Package names can be obfuscated in various ways, with increasing levels of 850 obfuscation and compactness. For example, consider the following classes: 851 <pre> 852 mycompany.myapplication.MyMain 853 mycompany.myapplication.Foo 854 mycompany.myapplication.Bar 855 mycompany.myapplication.extra.FirstExtra 856 mycompany.myapplication.extra.SecondExtra 857 mycompany.util.FirstUtil 858 mycompany.util.SecondUtil 859 </pre> 860 <p> 861 Let's assume the class name <code>mycompany.myapplication.MyMain</code> is the 862 main application class that is kept by the configuration. All other class names 863 can be obfuscated. 864 <p> 865 By default, packages that contain classes that can't be renamed aren't renamed 866 either, and the package hierarchy is preserved. This results in obfuscated 867 class names like these: 868 <pre> 869 mycompany.myapplication.MyMain 870 mycompany.myapplication.a 871 mycompany.myapplication.b 872 mycompany.myapplication.a.a 873 mycompany.myapplication.a.b 874 mycompany.a.a 875 mycompany.a.b 876 </pre> 877 <p> 878 The <a 879 href="usage.html#flattenpackagehierarchy"><code>-flattenpackagehierarchy</code></a> 880 option obfuscates the package names further, by flattening the package 881 hierarchy of obfuscated packages: 882 <pre> 883 -flattenpackagehierarchy 'myobfuscated' 884 </pre> 885 <p> 886 The obfuscated class names then look as follows: 887 <pre> 888 mycompany.myapplication.MyMain 889 mycompany.myapplication.a 890 mycompany.myapplication.b 891 myobfuscated.a.a 892 myobfuscated.a.b 893 myobfuscated.b.a 894 myobfuscated.b.b 895 </pre> 896 <p> 897 Alternatively, the <a 898 href="usage.html#repackageclasses"><code>-repackageclasses</code></a> option 899 obfuscates the entire packaging, by combining obfuscated classes into a single 900 package: 901 <pre> 902 -repackageclasses 'myobfuscated' 903 </pre> 904 The obfuscated class names then look as follows: 905 <pre> 906 mycompany.myapplication.MyMain 907 mycompany.myapplication.a 908 mycompany.myapplication.b 909 myobfuscated.a 910 myobfuscated.b 911 myobfuscated.c 912 myobfuscated.d 913 </pre> 914 <p> 915 Additionally specifying the <a 916 href="usage.html#allowaccessmodification"><code>-allowaccessmodification</code></a> 917 option allows access permissions of classes and class members to 918 be broadened, opening up the opportunity to repackage all obfuscated classes: 919 <pre> 920 -repackageclasses 'myobfuscated' 921 -allowaccessmodification 922 </pre> 923 The obfuscated class names then look as follows: 924 <pre> 925 mycompany.myapplication.MyMain 926 myobfuscated.a 927 myobfuscated.b 928 myobfuscated.c 929 myobfuscated.d 930 myobfuscated.e 931 myobfuscated.f 932 </pre> 933 <p> 934 The specified target package can always be the root package. For instance: 935 <pre> 936 -repackageclasses '' 937 -allowaccessmodification 938 </pre> 939 The obfuscated class names are then the shortest possible names: 940 <pre> 941 mycompany.myapplication.MyMain 942 a 943 b 944 c 945 d 946 e 947 f 948 </pre> 949 <p> 950 Note that not all levels of obfuscation of package names may be acceptable for 951 all code. Notably, you may have to take into account that your application may 952 contain <a href="#resourcefiles">resource files</a> that have to be adapted. 953 954 <a name="restructuring"> </a> 955 <h3>Restructuring the output archives</h3> 956 In simple applications, all output classes and resources files are merged into 957 a single jar. For example: 958 <pre> 959 -injars classes 960 -injars in1.jar 961 -injars in2.jar 962 -injars in3.jar 963 -outjars out.jar 964 </pre> 965 <p> 966 This configuration merges the processed versions of the files in the 967 <code>classes</code> directory and the three jars into a single output jar 968 <code>out.jar</code>. 969 <p> 970 If you want to preserve the structure of your input jars (and/or wars, ears, 971 zips, or directories), you can specify an output directory (or a war, an ear, 972 or a zip). For example: 973 <pre> 974 -injars in1.jar 975 -injars in2.jar 976 -injars in3.jar 977 -outjars out 978 </pre> 979 <p> 980 The input jars will then be reconstructed in the directory <code>out</code>, 981 with their original names. 982 <p> 983 You can also combine archives into higher level archives. For example: 984 <pre> 985 -injars in1.jar 986 -injars in2.jar 987 -injars in3.jar 988 -outjars out.war 989 </pre> 990 <p> 991 The other way around, you can flatten the archives inside higher level 992 archives into simple archives: 993 <pre> 994 -injars in.war 995 -outjars out.jar 996 </pre> 997 <p> 998 This configuration puts the processed contents of all jars inside 999 <code>in.war</code> (plus any other contents of <code>in.war</code>) into 1000 <code>out.jar</code>. 1001 <p> 1002 If you want to combine input jars (and/or wars, ears, zips, or directories) 1003 into output jars (and/or wars, ears, zips, or directories), you can group the 1004 <a href="usage.html#injars"><code>-injars</code></a> and <a 1005 href="usage.html#outjars"><code>-outjars</code></a> options. For example: 1006 <pre> 1007 -injars base_in1.jar 1008 -injars base_in2.jar 1009 -injars base_in3.jar 1010 -outjars base_out.jar 1011 1012 -injars extra_in.jar 1013 -outjars extra_out.jar 1014 </pre> 1015 <p> 1016 This configuration puts the processed results of all <code>base_in*.jar</code> 1017 jars into <code>base_out.jar</code>, and the processed results of the 1018 <code>extra_in.jar</code> into <code>extra_out.jar</code>. Note that only the 1019 order of the options matters; the additional whitespace is just for clarity. 1020 <p> 1021 This grouping, archiving, and flattening can be arbitrarily complex. ProGuard 1022 always tries to package output archives in a sensible way, reconstructing the 1023 input entries as much as required. 1024 1025 <a name="filtering"> </a> 1026 <h3>Filtering the input and the output</h3> 1027 1028 If you want even greater control, you can add filters to the input and the 1029 output, filtering out zips, ears, wars, jars, and/or ordinary files. For 1030 example, if you want to disregard certain files from an input jar: 1031 <pre> 1032 -injars in.jar(!images/**) 1033 -outjars out.jar 1034 </pre> 1035 <p> 1036 This configuration removes any files in the <code>images</code> directory and 1037 its subdirectories. 1038 <p> 1039 Such filters can be convenient for avoiding warnings about duplicate files in 1040 the output. For example, only keeping the manifest file from a first input jar: 1041 <pre> 1042 -injars in1.jar 1043 -injars in2.jar(!META-INF/MANIFEST.MF) 1044 -injars in3.jar(!META-INF/MANIFEST.MF) 1045 -outjars out.jar 1046 </pre> 1047 <p> 1048 Another useful application is speeding up the processing by ProGuard, by 1049 disregarding a large number of irrelevant classes in the runtime library jar: 1050 <pre> 1051 -libraryjars <java.home>/lib/rt.jar(java/**,javax/**) 1052 </pre> 1053 <p> 1054 The filter makes ProGuard disregard <code>com.sun.**</code> classes, for 1055 instance , which don't affect the processing of ordinary applications. 1056 <p> 1057 It is also possible to filter the jars (and/or wars, ears, zips) themselves, 1058 based on their names. For example: 1059 <pre> 1060 -injars in(**/acme_*.jar;) 1061 -outjars out.jar 1062 </pre> 1063 <p> 1064 Note the semi-colon in the filter; the filter in front of it applies to jar 1065 names. In this case, only <code>acme_*.jar</code> jars are read from the 1066 directory <code>in</code> and its subdirectories. Filters for war names, ear 1067 names, and zip names can be prefixed with additional semi-colons. All types of 1068 filters can be combined. They are orthogonal. 1069 <p> 1070 On the other hand, you can also filter the output, in order to control what 1071 content goes where. For example: 1072 <pre> 1073 -injars in.jar 1074 -outjars code_out.jar(**.class) 1075 -outjars resources_out.jar 1076 </pre> 1077 <p> 1078 This configuration splits the processed output, sending <code>**.class</code> 1079 files to <code>code_out.jar</code>, and all remaining files to 1080 <code>resources_out.jar</code>. 1081 <p> 1082 Again, the filtering can be arbitrarily complex, especially when combined with 1083 the grouping of input and output. 1084 1085 <a name="multiple"> </a> 1086 <h3>Processing multiple applications at once</h3> 1087 You can process several dependent or independent applications (or applets, 1088 midlets,...) in one go, in order to save time and effort. ProGuard's input and 1089 output handling offers various ways to keep the output nicely structured. 1090 <p> 1091 The easiest way is to specify your input jars (and/or wars, ears, zips, and 1092 directories) and a single output directory. ProGuard will then reconstruct the 1093 input in this directory, using the original jar names. For example, showing 1094 just the input and output options: 1095 <pre> 1096 -injars application1.jar 1097 -injars application2.jar 1098 -injars application3.jar 1099 -outjars processed_applications 1100 </pre> 1101 <p> 1102 After processing, the directory <code>processed_applications</code> will 1103 contain the processed application jars, with their original names. 1104 1105 <a name="incremental"> </a> 1106 <h3>Incremental obfuscation</h3> 1107 After having <a href="#application">processed an application</a>, e.g. 1108 ProGuard itself, you can still incrementally add other pieces of code that 1109 depend on it, e.g. the ProGuard GUI: 1110 <pre> 1111 -injars proguardgui.jar 1112 -outjars proguardgui_out.jar 1113 -injars proguard.jar 1114 -outjars proguard_out.jar 1115 -libraryjars <java.home>/lib/rt.jar 1116 -applymapping proguard.map 1117 1118 -keep public class proguard.gui.ProGuardGUI { 1119 public static void main(java.lang.String[]); 1120 } 1121 </pre> 1122 <p> 1123 We're reading both unprocessed jars as input. Their processed contents will go 1124 to the respective output jars. The <a 1125 href="usage.html#applymapping"><code>-applymapping</code></a> option then 1126 makes sure the ProGuard part of the code gets the previously produced 1127 obfuscation mapping. The final application will consist of the obfuscated 1128 ProGuard jar and the additional obfuscated GUI jar. 1129 <p> 1130 The added code in this example is straightforward; it doesn't affect the 1131 original code. The <code>proguard_out.jar</code> will be identical to the one 1132 produced in the initial processing step. If you foresee adding more complex 1133 extensions to your code, you should specify the options <a 1134 href="usage.html#useuniqueclassmembernames"><code>-useuniqueclassmembernames</code></a>, 1135 <a href="usage.html#dontshrink"><code>-dontshrink</code></a>, and <a 1136 href="usage.html#dontoptimize"><code>-dontoptimize</code></a> <i>in the 1137 original processing step</i>. These options ensure that the obfuscated base 1138 jar will always remain usable without changes. You can then specify the base 1139 jar as a library jar: 1140 <pre> 1141 -injars proguardgui.jar 1142 -outjars proguardgui_out.jar 1143 -libraryjars proguard.jar 1144 -libraryjars <java.home>/lib/rt.jar 1145 -applymapping proguard.map 1146 1147 -keep public class proguard.gui.ProGuardGUI { 1148 public static void main(java.lang.String[]); 1149 } 1150 </pre> 1151 1152 <a name="microedition"> </a> 1153 <h3>Preverifying class files for Java Micro Edition</h3> 1154 Even if you're not interested in shrinking, optimizing, and obfuscating your 1155 midlets, as shown in the <a href="#midlets">midlets example</a>, you can still 1156 use ProGuard to preverify the class files for Java Micro Edition. ProGuard 1157 produces slightly more compact results compared to the traditional external 1158 preverifier. 1159 <pre> 1160 -injars in.jar 1161 -outjars out.jar 1162 -libraryjars /usr/local/java/wtk2.1/lib/midpapi20.jar 1163 -libraryjars /usr/local/java/wtk2.1/lib/cldcapi11.jar 1164 1165 -dontshrink 1166 -dontoptimize 1167 -dontobfuscate 1168 1169 -microedition 1170 </pre> 1171 <p> 1172 We're not processing the input, just making sure the class files are 1173 preverified by targeting them at Java Micro Edition with the <a 1174 href="usage.html#microedition"><code>-microedition</code></a> option. Note 1175 that we don't need any <code>-keep</code> options to specify entry points; all 1176 class files are simply preverified. 1177 1178 <a name="upgrade"> </a> 1179 <h3>Upgrading class files to Java 6</h3> 1180 The following options upgrade class files to Java 6, by updating their 1181 internal version numbers and preverifying them. The class files can then be 1182 loaded more efficiently by the Java 6 Virtual Machine. 1183 <pre> 1184 -injars in.jar 1185 -outjars out.jar 1186 -libraryjars <java.home>/lib/rt.jar 1187 1188 -dontshrink 1189 -dontoptimize 1190 -dontobfuscate 1191 1192 -target 1.6 1193 </pre> 1194 <p> 1195 We're not processing the input, just retargeting the class files with the <a 1196 href="usage.html#target"><code>-target</code></a> option. They will 1197 automatically be preverified for Java 6 as a result. Note that we don't need 1198 any <code>-keep</code> options to specify entry points; all class files are 1199 simply updated and preverified. 1200 1201 <a name="deadcode"> </a> 1202 <h3>Finding dead code</h3> 1203 These options list unused classes, fields, and methods in the application 1204 <code>mypackage.MyApplication</code>: 1205 <pre> 1206 -injars in.jar 1207 -libraryjars <java.home>/lib/rt.jar 1208 1209 -dontoptimize 1210 -dontobfuscate 1211 -dontpreverify 1212 -printusage 1213 1214 -keep public class mypackage.MyApplication { 1215 public static void main(java.lang.String[]); 1216 } 1217 </pre> 1218 <p> 1219 We're not specifying an output jar, just printing out some results. We're 1220 saving some processing time by skipping the other processing steps. 1221 <p> 1222 The java compiler inlines primitive constants and String constants 1223 (<code>static final</code> fields). ProGuard would therefore list such fields 1224 as not being used in the class files that it analyzes, even if they <i>are</i> 1225 used in the source files. We can add a <a 1226 href="usage.html#keepclassmembers"><code>-keepclassmembers</code></a> option 1227 that keeps those fields a priori, in order to avoid having them listed: 1228 <pre> 1229 -keepclassmembers class * { 1230 static final % *; 1231 static final java.lang.String *; 1232 } 1233 </pre> 1234 1235 <a name="structure"> </a> 1236 <h3>Printing out the internal structure of class files</h3> 1237 These options print out the internal structure of all class files in the input 1238 jar: 1239 <pre> 1240 -injars in.jar 1241 1242 -dontshrink 1243 -dontoptimize 1244 -dontobfuscate 1245 -dontpreverify 1246 1247 -dump 1248 </pre> 1249 <p> 1250 Note how we don't need to specify the Java run-time jar, because we're not 1251 processing the input jar at all. 1252 1253 <a name="annotated"> </a> 1254 <h3>Using annotations to configure ProGuard</h3> 1255 1256 The traditional ProGuard configuration allows to keep a clean separation 1257 between the code and the configuration for shrinking, optimization, and 1258 obfuscation. However, it is also possible to define specific annotations, 1259 and then annotate the code to configure the processing. 1260 <p> 1261 You can find a set of such predefined annotations in the directory 1262 <code>examples/annotations/lib</code> in the ProGuard distribution. 1263 The annotation classes are defined in <code>annotations.jar</code>. The 1264 corresponding ProGuard configuration (or meta-configuration, if you prefer) 1265 is specified in <code>annotations.pro</code>. With these files, you can start 1266 annotating your code. For instance, a java source file 1267 <code>Application.java</code> can be annotated as follows: 1268 <pre> 1269 @KeepApplication 1270 public class Application { 1271 .... 1272 } 1273 </pre> 1274 <p> 1275 The ProGuard configuration file for the application can then be simplified by 1276 leveraging off these annotations: 1277 <pre> 1278 -injars in.jar 1279 -outjars out.jar 1280 -libraryjars <java.home>/lib/rt.jar 1281 1282 -include lib/annotations.pro 1283 </pre> 1284 <p> 1285 The annotations are effectively replacing the application-dependent 1286 <code>-keep</code> options. You may still wish to add traditional 1287 <code>-keep</code> options for processing <a href="#native">native 1288 methods</a>, <a href="#enumerations">enumerations</a>, <a 1289 href="#serializable">serializable classes</a>, and <a 1290 href="#annotations">annotations</a>. 1291 <p> 1292 The directory <code>examples/annotations</code> contains more examples that 1293 illustrate some of the possibilities. 1294 <p> 1295 1296 <hr> 1297 <address> 1298 Copyright © 2002-2009 1299 <a href="http://www.graphics.cornell.edu/~eric/">Eric Lafortune</a>. 1300 </address> 1301 </body> 1302 </html> 1303