Skip to content

Instantly share code, notes, and snippets.

@dyno
Created October 17, 2018 04:26
Show Gist options
  • Save dyno/a7fd7d062de9ba2a112b39882c39bd07 to your computer and use it in GitHub Desktop.
Save dyno/a7fd7d062de9ba2a112b39882c39bd07 to your computer and use it in GitHub Desktop.
Print out java class path to jars that contains it
spark_jars = "file://x.jar,file://y.jar"
jars = spark_jars.split(",")
from zipfile import ZipFile
from pathlib import Path
from collections import defaultdict
from pprint import pprint
libs = defaultdict(set)
for jar in sorted(jars):
namelist = ZipFile(jar[7:]).namelist()
for name in namelist:
if name.endswith(".class"):
path = Path(name).parent
class_path = str(path).replace("/", ".")
libs[class_path].add(jar)
for class_path, jars in sorted(libs.items()):
print(class_path, end=" => ")
print(" # ".join(jars))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment