Java ClassLoader loadXml()

Here you can find the source of loadXml()

Description

load Xml

License

Open Source License

Declaration

public static void loadXml() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;

public class Main {
    private static final String LOG4J_CONFIGURATION_FILE = "log4j.configurationFile";

    public static void loadXml() {
        File file = new File("log4j.xml");
        if (System.getProperty(LOG4J_CONFIGURATION_FILE) == null && file.exists()) {
            // set a default if file exist
            System.out.println(//  w w w. j  ava  2 s  .co  m
                    "Found log4j.xml file in current directory.  Setting log4j.configurationFile=log4j.xml");
            System.setProperty(LOG4J_CONFIGURATION_FILE, "log4j.xml");
        }
        checkForLog4jFile();
    }

    private static void checkForLog4jFile() {
        String logConfigFile = System.getProperty(LOG4J_CONFIGURATION_FILE);
        if (logConfigFile != null) { // if property set, then check that file can be found
            //System.out.println("  Checking that System property: log4j.configurationFile=" + logConfigFile+" is in classpath");
            {
                ClassLoader cl = ClassLoader.getSystemClassLoader();
                URL foundLogConfigFile = cl.getResource(logConfigFile);
                if (foundLogConfigFile == null) {
                    URL[] urls = ((URLClassLoader) cl).getURLs();
                    System.err.println("  !!! Could not find logging config file " + logConfigFile
                            + " in classpath: " + Arrays.toString(urls));
                    System.err.println("Remember to add path to log4j.xml file to classpath!");
                } else {
                    System.out.println("  Found in classpath: " + foundLogConfigFile);
                }
            }
        }
    }
}

Related

  1. loadProperties(final String configFile, final String chainProperty)
  2. loadProperties(final String location)
  3. loadProperties(String propFile)
  4. loadPropertiesFromFile(File parent)
  5. loadTextFile(final String location)
  6. locateFile(String name)
  7. read(String fileName)
  8. readFromFile(Object obj, String fileName)
  9. readSampleJson(String name)