public final class JkUrlClassLoader
extends java.lang.Object
URLClassLoader offering convenient methods and fluent
interface to deal with URLClassLoader.| Modifier and Type | Field and Description |
|---|---|
static java.nio.file.PathMatcher |
CLASS_FILE_FILTER
A
PathMatcher accepting only .class files. |
| Modifier and Type | Method and Description |
|---|---|
void |
addEntries(java.lang.Iterable<java.nio.file.Path> paths)
Same as
addEntries(Path, Path, Path...). |
void |
addEntries(java.nio.file.Path path1,
java.nio.file.Path path2,
java.nio.file.Path... others)
Add a new entry to this class loader.
|
static java.lang.String |
findMainClass(java.nio.file.Path classDirOrJar)
Returns the first class having a main method from the specified class
directory or Jar.
|
JkUrlClassLoader |
getChild(java.lang.Iterable<java.nio.file.Path> extraEntries)
Creates a
JkClassLoader, child of this one and having the specified entries. |
java.lang.ClassLoader |
getDelegate()
Return the
URLClassLoader wrapped by this object. |
JkClasspath |
getDirectClasspath()
Returns the classpath of this classloader without mentioning classpath of
the parent classloaders.
|
JkClasspath |
getFullClasspath()
Returns the complete classpath of this classloader.
|
JkUrlClassLoader |
getParent()
Returns the class loader parent of this one.
|
JkUrlClassLoader |
getSibling(java.lang.Iterable<java.net.URL> fileOrUrls) |
JkUrlClassLoader |
getSibling(java.net.URL... fileOrUrls)
Creates a
JkClassLoader loader having the same parent and
the same entries as this one plus the specified entries. |
JkUrlClassLoader |
getSiblingPrintingSearchedClasses(java.util.Set<java.lang.String> searchedClassContainer)
Returns a getSibling of this class loader that outputs every searched class.
|
JkUrlClassLoader |
getSiblingWithOptional(java.net.URL... fileOrUrls)
Same as
getSibling(URL...) but more tolerant about the input. |
static java.nio.file.Path |
getUrlCacheDir()
Get the directory where are cached urls.
|
void |
loadAllServices()
Reloads all J2SE service providers.
|
java.util.Set<java.lang.Class<?>> |
loadClasses(java.lang.String... globPatterns)
Loads all class having a relative path matching the supplied ANT pattern.
|
java.util.Set<java.lang.Class<?>> |
loadClassesIn(JkPathTreeSet jkPathTreeSet)
Returns all classes of this
classloader that are defined
inside the provided JkPathTreeSet. |
java.util.Set<java.lang.Class<?>> |
loadClassesInEntries(java.nio.file.PathMatcher entryFilter)
Returns all classes of this
classloader that are defined in
entries matching the specified fileFilter. For example : if you want
to load all classes that are defined in folder and not andAccept jar file, you
have to provide a FileFilter which includes only
directories. |
<T> java.lang.Class<? extends T> |
loadFromNameOrSimpleName(java.lang.String name,
java.lang.Class<T> superClassArg)
Loads the class having the specified full name or the specified simple
name.
|
static JkUrlClassLoader |
of(java.net.URLClassLoader urlClassLoader) |
static JkUrlClassLoader |
ofCurrent()
Returns a
JkUrlClassLoader wrapping the current thread context classloader. |
static JkUrlClassLoader |
ofLoaderOf(java.lang.Class<?> clazz)
Returns a
JkUrlClassLoader wrapping the class loader having loaded
the specified class. |
static JkUrlClassLoader |
ofSystem()
Returns a
JkUrlClassLoader wrapping the ofSystem class loader. |
JkClassLoader |
toJkClassLoader() |
java.lang.String |
toString() |
public static final java.nio.file.PathMatcher CLASS_FILE_FILTER
PathMatcher accepting only .class files.public static JkUrlClassLoader of(java.net.URLClassLoader urlClassLoader)
public static JkUrlClassLoader ofCurrent()
JkUrlClassLoader wrapping the current thread context classloader.Class.getClassLoader()public static JkUrlClassLoader ofSystem()
JkUrlClassLoader wrapping the ofSystem class loader.ClassLoader.getSystemClassLoader()public static JkUrlClassLoader ofLoaderOf(java.lang.Class<?> clazz)
JkUrlClassLoader wrapping the class loader having loaded
the specified class.public static java.nio.file.Path getUrlCacheDir()
public java.lang.ClassLoader getDelegate()
URLClassLoader wrapped by this object.public JkUrlClassLoader getParent()
public JkUrlClassLoader getChild(java.lang.Iterable<java.nio.file.Path> extraEntries)
JkClassLoader, child of this one and having the specified entries.public JkUrlClassLoader getSibling(java.net.URL... fileOrUrls)
JkClassLoader loader having the same parent and
the same entries as this one plus the specified entries. URL entries that
are not file are transformed to file (created in temp folder).public JkUrlClassLoader getSibling(java.lang.Iterable<java.net.URL> fileOrUrls)
getSibling(Iterable)public JkUrlClassLoader getSiblingWithOptional(java.net.URL... fileOrUrls)
getSibling(URL...) but more tolerant about the input. If
one of the specified entry is not valid, then it is simply ignored.public JkUrlClassLoader getSiblingPrintingSearchedClasses(java.util.Set<java.lang.String> searchedClassContainer)
getSibling(Iterable)public JkClasspath getDirectClasspath()
public JkClasspath getFullClasspath()
public JkClassLoader toJkClassLoader()
public java.util.Set<java.lang.Class<?>> loadClassesInEntries(java.nio.file.PathMatcher entryFilter)
classloader that are defined in
entries matching the specified fileFilter. For example : if you want
to load all classes that are defined in folder and not andAccept jar file, you
have to provide a FileFilter which includes only
directories.entryFilter - The classpath entry filter. Can be null.public java.util.Set<java.lang.Class<?>> loadClasses(java.lang.String... globPatterns)
my.packAllArtifacts or its sub package, then you have to supply a the
following pattern my/packAllArtifacts/**/*.public java.util.Set<java.lang.Class<?>> loadClassesIn(JkPathTreeSet jkPathTreeSet)
classloader that are defined
inside the provided JkPathTreeSet.loadClassesInEntries(PathMatcher)public <T> java.lang.Class<? extends T> loadFromNameOrSimpleName(java.lang.String name,
java.lang.Class<T> superClassArg)
null if no class matches. For example :
loadFromNameOrSimpleName("MyClass", null) may returns
my.packAllArtifacts.MyClass class.name - The full name or the simple value of the class to loadsuperClassArg - If not null, the search is narrowed to classes/interfaces
children of this class/interface.null.public static java.lang.String findMainClass(java.nio.file.Path classDirOrJar)
null if no such class found.public java.lang.String toString()
toString in class java.lang.Objectpublic void addEntries(java.nio.file.Path path1,
java.nio.file.Path path2,
java.nio.file.Path... others)
public void addEntries(java.lang.Iterable<java.nio.file.Path> paths)
addEntries(Path, Path, Path...).paths - As Path class implements Iterable the argument can be a single Path
instance, if so it will be interpreted as a list containing a single element which is this argument.public void loadAllServices()