Java Utililty Methods ClassLoader Load

List of utility methods to do ClassLoader Load

Description

The list of methods to do ClassLoader Load are organized into topic(s).

Method

ListgetFullPathByPkg(String pkg)
get Full Path By Pkg
List<String> result = new ArrayList<>();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
String packagePath = pkg.replace(".", "/");
URL url = loader.getResource(packagePath);
File dir = new File(url.getPath());
StringBuilder str = new StringBuilder();
for (File f : dir.listFiles()) {
    str.append(pkg).append(".");
...
StringgetImageFilename(String name)
Adds the path of the images directory to the name of the image.
String result;
String dir;
URL url;
result = null;
dir = "com/github/fracpete/screencast4j/images/";
try {
    url = ClassLoader.getSystemClassLoader().getResource(dir + name);
    if (url != null)
...
InputStreamgetInputStream(String name)
get Input Stream
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream is = null;
if ((name != null) && (name.indexOf(":/") > -1)) {
    try {
        is = new URL(name).openStream();
    } catch (Exception e) {
URL url = classLoader.getResource(name);
if (is == null) {
    try {
        is = classLoader.getResourceAsStream(name);
    } catch (Exception e) {
if (is == null) {
    try {
        is = classLoader.getResourceAsStream('/' + name);
    } catch (Exception e) {
if (is == null) {
    try {
        is = classLoader.getResourceAsStream("META-INF/" + name);
    } catch (Exception e) {
if (is == null) {
    try {
        is = new FileInputStream(name);
    } catch (FileNotFoundException e) {
return is;
StringgetLibKoyaVersion()
get Lib Koya Version
Enumeration resEnum;
try {
    resEnum = Thread.currentThread().getContextClassLoader().getResources("META-INF/build.properties");
    while (resEnum.hasMoreElements()) {
        try {
            URL url = (URL) resEnum.nextElement();
            InputStream is = url.openStream();
            Properties prop = new Properties();
...
FilegetLocalFile(final String aLocalPath)
get Local File
try {
    return new File(ClassLoader.getSystemResource("").toURI().getPath(), aLocalPath);
} catch (final URISyntaxException uiUriSyntaxException) {
    throw new IllegalStateException("This is a critical error. Please report it.", uiUriSyntaxException);
URLgetLog4jPropertiesLocation()
get Logj Properties Location
URL systemResource = ClassLoader.getSystemResource(LOG4J_PROPERTIES);
return systemResource;
StringgetManifestInfo()
get Manifest Info
Enumeration resEnum;
try {
    resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
    while (resEnum.hasMoreElements()) {
        try {
            URL url = (URL) resEnum.nextElement();
            InputStream is = url.openStream();
            if (is != null) {
...
StringgetMetadataSpecialSymbolsXml()
get Metadata Special Symbols Xml
return new File(ClassLoader.getSystemClassLoader().getResource("dpp/metadata-special-symbols.xml").toURI())
        .getAbsolutePath();
StringgetPath(final String fileName)
get Path
final URL url = ClassLoader.getSystemResource(fileName);
if (url != null) {
    return url.getFile();
} else {
    throw new IllegalArgumentException(
            "File " + fileName + " does not exist on the classpath: " + CLASSPATH);
StringgetPath(String resoureLocation)
This function returns the absolute path of a class path resource.
return getContextClassLoader().getResource(resoureLocation).toURI().getPath();