### JarJar Keep Rule Example Source: https://github.com/shevek/jarjar/blob/master/README.md Example of a keep rule to mark classes as roots, ensuring they and their dependencies are preserved. ```plaintext keep com.example.api.** ``` -------------------------------- ### JarJar Rename Rule Example Source: https://github.com/shevek/jarjar/blob/master/README.md Example of a rename rule using wildcards to rename classes. '@1' references the first wildcard match. ```plaintext rule com.example.** com.example.new.@1 ``` -------------------------------- ### Find JAR-Level Dependencies with DependencyFinder Source: https://context7.com/shevek/jarjar/llms.txt Use DependencyFinder.run() with TextDependencyHandler and Level.JAR to get a summary of JAR-to-JAR dependencies. This provides a higher-level view compared to class-level analysis. ```java // JAR-level summary DependencyHandler jarHandler = new TextDependencyHandler(System.out, DependencyHandler.Level.JAR); new DependencyFinder().run(jarHandler, appPath, guavaPath); ``` -------------------------------- ### JarJar Zap Rule Example Source: https://github.com/shevek/jarjar/blob/master/README.md Example of a zap rule to remove all classes matching a specific pattern. ```plaintext zap com.example.internal.** ``` -------------------------------- ### JarJar Command Line: Help Source: https://github.com/shevek/jarjar/blob/master/README.md Display the help message for the JarJar command-line tool. ```bash java -jar jarjar.jar [help] ``` -------------------------------- ### Command-Line: Process JAR with Rules Source: https://context7.com/shevek/jarjar/llms.txt Repackages an input JAR by applying transformation rules from a specified file. This command overwrites any existing output file. ```bash # Build the fat jar first ./gradlew :jarjar-command:shadowJar # Create rules.txt cat > rules.txt <<'EOF' rule org.jaxen.** com.example.private.jaxen.@1 rule com.google.guava.** com.example.private.guava.@1 zap org.apache.thrift.** keep com.example.myapp.** EOF # Run the process command java -jar jarjar-command/build/libs/jarjar-command-all.jar \ --mode process \ --rules rules.txt \ --output output-shaded.jar \ input-library.jar # Expected: output-shaded.jar written with renamed classes # org.jaxen.XPath → com.example.private.jaxen.XPath # com.google.guava.collect.ImmutableList → com.example.private.guava.collect.ImmutableList # org.apache.thrift.* classes removed entirely ``` -------------------------------- ### Repackage JAR with Rules from File or Programmatically Source: https://context7.com/shevek/jarjar/llms.txt Demonstrates how to use DefaultJarProcessor to load rules from a file or define them programmatically. Use this for complex repackaging tasks involving class deletion, renaming, and transitive keeping. ```java import com.tonicsystems.jarjar.classpath.ClassPath; import com.tonicsystems.jarjar.transform.JarTransformer; import com.tonicsystems.jarjar.transform.config.ClassDelete; import com.tonicsystems.jarjar.transform.config.ClassRename; import com.tonicsystems.jarjar.transform.config.ClassKeepTransitive; import com.tonicsystems.jarjar.transform.config.RulesFileParser; import com.tonicsystems.jarjar.transform.jar.DefaultJarProcessor; import java.io.File; import java.util.Arrays; public class RepackageExample { public static void main(String[] args) throws Exception { File inputJar = new File("guava-18.0.jar"); File outputJar = new File("guava-shaded.jar"); File rulesFile = new File("rules.txt"); // --- Option A: load rules from a text file --- DefaultJarProcessor processor = new DefaultJarProcessor(); RulesFileParser.parse(processor, rulesFile); // --- Option B: add rules programmatically --- DefaultJarProcessor processor2 = new DefaultJarProcessor(); // Delete test utilities processor2.addClassDelete(new ClassDelete("com.google.common.testing.**")); // Rename surviving classes processor2.addClassRename(new ClassRename("com.google.**", "org.example.private.google.@1")); // Keep only classes reachable from a specific root processor2.addClassKeepTransitive(new ClassKeepTransitive("org.example.private.google.**")); // Run the transformation JarTransformer transformer = new JarTransformer(outputJar, processor2); transformer.transform(new ClassPath(new File("."), Arrays.asList(inputJar))); System.out.println("Written: " + outputJar); // guava-shaded.jar now contains only classes reachable from // org.example.private.google.** with all references updated. } } ``` -------------------------------- ### JarJar Command Line: Find Dependencies Source: https://github.com/shevek/jarjar/blob/master/README.md Analyze dependencies between classpath components. Specify a level (class or jar) and one or two classpaths to find dependencies. ```bash java -jar jarjar.jar find [] ``` -------------------------------- ### Jar Jar Links Rules File Format Source: https://context7.com/shevek/jarjar/llms.txt Defines rules for class deletion, renaming, and keeping specific classes. Use `**` for any package substring and `*` for a single component. Backreferences `@1`, `@2`, etc., refer to wildcard captures. ```text # rules.txt # Rename all classes under org.jaxen into a private namespace rule org.jaxen.** com.example.shaded.jaxen.@1 # Rename a single-level package component (no dots) rule org.json.* com.example.shaded.json.@1 # Delete the entire Apache Thrift namespace (zap runs first) zap org.apache.thrift.** # Keep only classes reachable from this entry point keep com.example.myapp.Main ``` -------------------------------- ### DependencyFinder.run() Source: https://context7.com/shevek/jarjar/llms.txt Analyzes dependencies between two ClassPaths and reports them via a DependencyHandler. The Level enum controls the granularity of the analysis. ```APIDOC ## DependencyFinder.run() ### Description Accepts a `DependencyHandler` callback, a "from" `ClassPath`, and a "to" `ClassPath`. For every class in the "from" path that references a class in the "to" path, the handler is called with the dependency. `TextDependencyHandler` prints results to any `PrintStream`. The `Level` enum controls granularity: `CLASS` for individual class pairs, `JAR` for archive-level summaries. ### Method Signature `DependencyFinder.run(DependencyHandler handler, ClassPath fromPath, ClassPath toPath)` ### Parameters #### Path Parameters - **handler** (`DependencyHandler`) - Required - A callback to handle detected dependencies. - **fromPath** (`ClassPath`) - Required - The source ClassPath to analyze. - **toPath** (`ClassPath`) - Required - The target ClassPath to check for references. ### Usage Example ```java import com.tonicsystems.jarjar.classpath.ClassPath; import com.tonicsystems.jarjar.dependencies.DependencyFinder; import com.tonicsystems.jarjar.dependencies.DependencyHandler; import com.tonicsystems.jarjar.dependencies.TextDependencyHandler; import java.io.File; import java.util.Arrays; ClassPath appPath = new ClassPath(new File("."), Arrays.asList(new File("myapp.jar"))); ClassPath guavaPath = new ClassPath(new File("."), Arrays.asList(new File("guava-18.0.jar"))); // Print class-level dependencies from myapp.jar into guava.jar DependencyHandler handler = new TextDependencyHandler(System.out, DependencyHandler.Level.CLASS); new DependencyFinder().run(handler, appPath, guavaPath); // Expected output: // com/example/app/Service -> com/google/common/collect/ImmutableList // com/example/app/Utils -> com/google/common/base/Preconditions // JAR-level summary DependencyHandler jarHandler = new TextDependencyHandler(System.out, DependencyHandler.Level.JAR); new DependencyFinder().run(jarHandler, appPath, guavaPath); // Expected output: // myapp.jar -> guava-18.0.jar ``` ### Response This method does not return a value directly. Dependencies are reported via the `DependencyHandler` callback. ``` -------------------------------- ### Command-Line: Dump String Literals from Classes Source: https://context7.com/shevek/jarjar/llms.txt Scans `.class` files to extract all string literals from bytecode, optionally including line numbers if debug information is present. Useful for auditing string constant references. ```bash java -jar jarjar-command/build/libs/jarjar-command-all.jar \ --mode strings \ mylib.jar # Expected output (with debug info): # com/example/MyClass.java:42: "com.google.common.collect.ImmutableList" # com/example/MyClass.java:87: "org.jaxen.XPath" ``` -------------------------------- ### JarJar Command Line: Dump Strings Source: https://github.com/shevek/jarjar/blob/master/README.md Use the command line to dump all string literals from classes on a given classpath. Line numbers are included if debug information is present. ```bash java -jar jarjar.jar strings ``` -------------------------------- ### Command-Line: Find JAR Dependencies Source: https://context7.com/shevek/jarjar/llms.txt Analyzes dependency relationships within or between JARs. Use `--level class` for class-to-class dependencies or `--level jar` for jar-to-jar graphs. Omit `--from` to report self-dependencies. ```bash # Print all jar-level dependencies within a single jar java -jar jarjar-command/build/libs/jarjar-command-all.jar \ --mode find \ --level jar \ hive-exec.jar # Print class-level dependencies FROM app.jar INTO guava.jar java -jar jarjar-command/build/libs/jarjar-command-all.jar \ --mode find \ --level class \ --from app.jar \ guava.jar # Expected output (class level): # com/example/app/Service -> com/google/common/collect/ImmutableList # com/example/app/Utils -> com/google/common/base/Preconditions ``` -------------------------------- ### JarJar Command Line: Process Jar Source: https://github.com/shevek/jarjar/blob/master/README.md Transform an input JAR file based on rules defined in a separate file, writing the result to an output JAR. Existing output files will be overwritten. ```bash java -jar jarjar.jar process ``` -------------------------------- ### Find Class-Level Dependencies with DependencyFinder Source: https://context7.com/shevek/jarjar/llms.txt Use DependencyFinder.run() with TextDependencyHandler and Level.CLASS to print individual class-level dependencies between two ClassPath objects. Ensure necessary JARs are included in the ClassPath. ```java import com.tonicsystems.jarjar.classpath.ClassPath; import com.tonicsystems.jarjar.dependencies.DependencyFinder; import com.tonicsystems.jarjar.dependencies.DependencyHandler; import com.tonicsystems.jarjar.dependencies.TextDependencyHandler; import java.io.File; import java.util.Arrays; ClassPath appPath = new ClassPath(new File("."), Arrays.asList(new File("myapp.jar"))); ClassPath guavaPath = new ClassPath(new File("."), Arrays.asList(new File("guava-18.0.jar"))); // Print class-level dependencies from myapp.jar into guava.jar DependencyHandler handler = new TextDependencyHandler(System.out, DependencyHandler.Level.CLASS); new DependencyFinder().run(handler, appPath, guavaPath); ``` -------------------------------- ### Repackage Dependencies with Gradle Source: https://github.com/shevek/jarjar/blob/master/README.md Use the jarjar.repackage dependency configuration in Gradle to embed and transform classes from specified dependencies. Supports class deletion and renaming. ```gradle dependencies { // Use jarjar.repackage in place of a dependency notation. compile jarjar.repackage { from 'com.google.guava:guava:18.0' classDelete "com.google.common.base.**" classRename "com.google.**" "org.private.google.@1" } } ``` -------------------------------- ### Define JarJarTask Ant Task Source: https://github.com/shevek/jarjar/blob/master/README.md Configure the Ant build to use JarJarTask for creating distributable JARs. Ensure jarjar.jar is in the classpath. ```xml ``` -------------------------------- ### Ant JarJar Task Configuration Source: https://context7.com/shevek/jarjar/llms.txt Configure the Ant jarjar task to rename packages, remove specific classes, and keep only essential classes. Ensure jarjar.jar is in the lib directory. ```xml ``` -------------------------------- ### Gradle JarJar Repackage Guava Source: https://context7.com/shevek/jarjar/llms.txt Use the Gradle jarjar plugin to repackage Guava into a private namespace and delete test utilities. Ensure the plugin is applied in buildscript dependencies. ```groovy // build.gradle buildscript { repositories { mavenCentral() } dependencies { classpath 'org.anarres.jarjar:jarjar-gradle:1.1.1' } } apply plugin: 'java' apply plugin: 'org.anarres.jarjar' dependencies { // Repackage Guava into a private namespace, deleting test utilities compile jarjar.repackage { from 'com.google.guava:guava:18.0' // Delete classes we don't want included classDelete "com.google.common.testing.**" // Rename the surviving classes into a private namespace classRename "com.google.**" "org.example.private.google.@1" } // Repackage a large transitive dependency graph compile jarjar.repackage { from('org.apache.hive:hive-exec:0.13.0') { exclude group: 'net.hydromatic', module: 'optiq-core' } // Pass commons jars through unchanged (no renaming) archiveBypass "commons*.jar" // Drop slf4j — provided by the host application archiveExclude "slf4j*.jar" classDelete "org.apache.thrift.**" classRename 'org.json.**', 'org.example.hive.json.@1' classRename 'com.google.**', 'org.example.hive.google.@1' classRename 'com.esotericsoftware.kryo.**', 'org.example.hive.kryo.@1' } } ``` -------------------------------- ### Transform Multiple JARs with Renaming Rules Source: https://context7.com/shevek/jarjar/llms.txt Orchestrates the repackaging of multiple input JARs into a single output JAR using JarTransformer. This is useful for merging libraries while applying consistent renaming rules. ```java import com.tonicsystems.jarjar.classpath.ClassPath; import com.tonicsystems.jarjar.transform.JarTransformer; import com.tonicsystems.jarjar.transform.jar.DefaultJarProcessor; import com.tonicsystems.jarjar.transform.config.ClassRename; import java.io.File; import java.util.Arrays; File outputJar = new File("merged-shaded.jar"); DefaultJarProcessor processor = new DefaultJarProcessor(); processor.addClassRename(new ClassRename("org.jaxen.**", "com.example.jaxen.@1")); processor.setSkipManifest(false); // include MANIFEST.MF (default) // Transform multiple input jars in one pass ClassPath inputs = new ClassPath( new File("."), Arrays.asList( new File("jaxen-1.1.6.jar"), new File("saxpath-1.0.jar") ) ); JarTransformer transformer = new JarTransformer(outputJar, processor); transformer.transform(inputs); // merged-shaded.jar contains both jars with org.jaxen.* renamed throughout ``` -------------------------------- ### Include and Rename Jar Dependencies with Ant Source: https://github.com/shevek/jarjar/blob/master/README.md Embed external JARs and rename their classes using JarJarTask's rule element. The pattern uses wildcards to match class names, and result specifies the new name. ```xml ``` -------------------------------- ### JarJar Rule Types Source: https://github.com/shevek/jarjar/blob/master/README.md Defines the three types of rules available in JarJar: rule (rename), zap (remove), and keep (preserve). ```plaintext rule zap keep ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.