GitXplorerGitXplorer
b

shakyboi

public
13 stars
2 forks
0 issues

Commits

List of commits on branch main.
Unverified
52883f3456bacabeaf87212cae653b0d61735f3c

Cosmetics.

bbadlogic committed 4 years ago
Unverified
94b919739feefef62eca3dc1c30ec6ee2bc0c596

Time individual stages.

bbadlogic committed 4 years ago
Unverified
fe1f621b8e205a1168e0e248b81cc821ad0fa9a2

Generate ClassNode.referencedBy, better reports, test script.

bbadlogic committed 4 years ago
Unverified
1890071130dbed3c7f75f90d105e7cb5e72fa05b

Implement CLI driver.

bbadlogic committed 4 years ago
Unverified
c222ab16f12658bb71571be5b25fba8d4cf0454d

Renamed ClassLookup -> Lookup, added methods to find resources and list all files.

bbadlogic committed 4 years ago
Unverified
cd0751474fcc5308d321909ca0380bf3a0bf8845

Renaming for better understanding.

bbadlogic committed 4 years ago

README

The README file for this repository.

Shakyboi

A Java class tree shaker to reduce your uber-jar file sizes by removing unused classes. See the blog post series on the motivation and implementation details.

Building

mvn package

This will generate target/shakyboi.jar

Usage

Run java -jar shakyboi.jar to see the help text.

A simple usage example:

java -jar shakyboi.jar \
    --app myapp.jar \
    --root my.app.MainClass \
    --output myapp-shaky.jar

This will read myapp.jar, trace all class dependencies starting at the root class my.app.MainClass, and output all resource files found in myapp.jar as well as all .class files of all classes reachable from my.app.MainClass to myapp-shaky.jar. You can specify multiple -app sources, either .jar files or directories.

Shakyboi is unable to find classes only referred to via reflection. For this case, add these classes as roots.

java -jar shakyboi.jar \
    --app myapp.jar \
    --root my.app.MainClass \
    --root my.app.ClassReferencedByReflection \
    --output myapp-shaky.jar

You can also specify root classes are patterns.

java -jar shakyboi.jar \
    --app myapp.jar \
    --root my.app.MainClass \
    --root my.app.**.*Reflection \
    --output myapp-shaky.jar

Shakyboi can also generate a report on included and removed classes, either as HTML or JSON. Use the --html-report <file> and --json-report <file> options to specify where to output the reports.

java -jar shakyboi.jar \
    --app myapp.jar \
    --root my.app.MainClass \
    --root my.app.**.*Reflection \
    --output myapp-shaky.jar \
    --html-report report.html \
    --json-report report.json

Shakyboi needs to be able to find bootstrap classes referenced by your app's classes, like java.lang.Object. These are usually found in the Java Runtime Class Library that ships with your JRE or JDK. By default, Shakyboi uses the class library of the JRE/JDK it is executed with. You can specify bootstrap class lookups explicitely via --bootstrap.

java -jar shakyboi.jar \
    --app myapp.jar \
    --root my.app.MainClass \
    --root my.app.**.*Reflection \
    --output myapp-shaky.jar \
    --html-report report.html \
    --json-report report.json \
    --bootstrap /opt/jdk8/lib/rt.jar