LinuxCommandLibrary

grepjar

Search JAR files for specified patterns

SYNOPSIS

grepjar [-h|-i|-l|-v] [-d dir] pattern [jarfiles...]

PARAMETERS

-h
    Display help and exit

-i
    Ignore case distinctions in pattern matching

-l
    List only JAR filenames containing matches

-v
    Invert match: select non-matching lines

-d dir
    Change to directory dir before searching JARs

DESCRIPTION

grepjar is a specialized command-line utility designed to search for patterns within JAR (Java Archive) and ZIP files without extracting their contents. It emulates the behavior of the standard grep command but operates on archive entries, making it invaluable for Java developers searching for classes, resources, or strings across multiple JAR files.

By scanning the internal structure of JARs, it lists matching file paths within the archives, such as jarfile.jar:com/example/Class.class. This avoids the need for manual extraction using tools like jar or unzip, saving time in large projects or dependency scans.

Common use cases include locating specific Java classes, finding dependencies, or auditing JARs for security patterns. It supports basic grep-like options for case-insensitivity, inversion, and file listing. Note that it relies on Perl and requires JAR files as input.

CAVEATS

Requires Perl; limited to JAR/ZIP files; no regex support beyond basic patterns; may miss compressed entries in some archives.

EXAMPLE USAGE

grepjar -i Exception *.jar
grepjar -l MyClass lib/*.jar

OUTPUT FORMAT

Displays 'jarfile.jar:path/to/entry' for matches.

HISTORY

Developed as a Perl script by Lou Grammas in the early 2000s to aid Java developers. Gained popularity in open-source communities; available via packages like Debian's grepjar or direct downloads from GitHub mirrors.

SEE ALSO

grep(1), jar(1), unzip(1), zipinfo(1), find(1)

Copied to clipboard