Here you can find the source of CreateLogbackXML(OutputStream out)
private static void CreateLogbackXML(OutputStream out) throws IOException
//package com.java2s; //License from project: Apache License import java.io.InputStream; import java.io.OutputStream; import java.io.FileInputStream; import java.io.IOException; import java.net.URL; import java.util.Enumeration; import java.util.jar.JarEntry; public class Main { private static void CreateLogbackXML(OutputStream out) throws IOException { Enumeration<URL> logback_xml_urls; logback_xml_urls = Thread.currentThread().getContextClassLoader() .getResources("logback.xml"); while (logback_xml_urls.hasMoreElements()) { URL logback_xml_url = logback_xml_urls.nextElement(); if (logback_xml_url.getProtocol().equals("file")) { //Case 1: logback.xml as simple file FileInputStream is = new FileInputStream( logback_xml_url.getPath()); while (is.available() > 0) { out.write(is.read()); }//from ww w .j a v a2s. c o m is.close(); return; } if (logback_xml_url.getProtocol().equals("jar")) { //Case 2: logback.xml included in a JAR String path = logback_xml_url.getPath(); String jarFile = path.substring("file:".length(), path.indexOf("!")); java.util.jar.JarFile jar = new java.util.jar.JarFile( jarFile); Enumeration<JarEntry> enums = jar.entries(); while (enums.hasMoreElements()) { java.util.jar.JarEntry file = enums.nextElement(); if (!file.isDirectory() && file.getName().equals("logback.xml")) { InputStream is = jar.getInputStream(file); // get the input stream while (is.available() > 0) { out.write(is.read()); } is.close(); jar.close(); return; } } jar.close(); } } throw new IOException("Failed to locate a logback.xml"); } }