public class ClassLoaderUtils extends Object
Class to deal with dynamic Java class loading from .class/.jar files.
Modifier and Type | Method and Description |
---|---|
static <T> List<Class<T>> |
getClassesFromFile(File file,
Class<T> _class,
ClassLoader classLoaderToUse)
Returns a list of Java classes from a .class/.jar file implementing/extending the specified class.
|
static Pair<File,String> |
getClasspathAndQualifiedNameFromClassFile(File classFile)
Tries to guess what are the classpath and fully qualified name of a .class Java file
|
static FileFilter |
getFileFilter()
Returns the file filter for this class loader.
|
static <T> T |
getInstance(File file,
String className,
Class<T> _class,
ClassLoader classLoaderToUse)
Returns a new instance for the desired class from a given file.
|
static <T> T |
getInstance(File file,
String className,
Class<T> _class,
URLClassLoader classLoaderToUpdate)
Returns a new instance for the desired class from a given file.
|
static Pair<String,String> |
getPackageAndClassName(String fullyQualifiedClassName)
Given a fully qualified class name returns the package and class names.
|
public static <T> List<Class<T>> getClassesFromFile(File file, Class<T> _class, ClassLoader classLoaderToUse)
T
- Class typefile
- .class/.jar file_class
- Reference to the classclassLoaderToUse
- If null, creates a new class loader. If not, loads classes from it_class
public static Pair<File,String> getClasspathAndQualifiedNameFromClassFile(File classFile)
classFile
- .class filepublic static FileFilter getFileFilter()
public static <T> T getInstance(File file, String className, Class<T> _class, ClassLoader classLoaderToUse)
T
- Class typefile
- .class/.jar fileclassName
- the class name_class
- Reference to the classclassLoaderToUse
- If null, creates a new class loader. If not, loads classes from itpublic static <T> T getInstance(File file, String className, Class<T> _class, URLClassLoader classLoaderToUpdate)
T
- Class typefile
- .class/.jar fileclassName
- the class name_class
- Reference to the classclassLoaderToUpdate
- Class loader to be updatedpublic static Pair<String,String> getPackageAndClassName(String fullyQualifiedClassName)
fullyQualifiedClassName
- Fully qualified class nameString
array in which the first element is the package name (empty String
means no package), and the second one is the class nameCopyright © 2018. All rights reserved.