JarLocator

object JarLocator

Resolve a CodeSource or module-reference location to the real backing jar File, across loaders.

Fabric (Knot) and dev give a plain file: URL — File(uri) works. NeoForge/Forge wrap the mod jar in securejarhandler's union: filesystem, whose URI File(uri) rejects with IllegalArgumentException: URI scheme is not "file". For those we ask the union filesystem for its real backing path via its public getPrimaryPath(). It's reflective because cpw.mods.niofs.union.UnionFileSystem is a loader class not on the vanilla/common compile classpath; a string-parse of the wrapped URI is the last-resort fallback.

Functions

Link copied to clipboard
fun toJarFile(uri: URI?): File?

The real jar/dir File backing a location uri, or null. Module reference locations (java.lang.module.ModuleReference.location) arrive as URIs, and a union:/jar: URI has no URL stream handler (so URI.toURL() throws) — so resolve straight from the URI.

The real jar/dir File backing loc, or null if it can't be resolved.