Java ClassLoader Load getProperties(String bundleName, String fileName)

Here you can find the source of getProperties(String bundleName, String fileName)

Description

get Properties

License

Open Source License

Declaration

public static Properties getProperties(String bundleName, String fileName) 

Method Source Code


//package com.java2s;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;

public class Main {

    public static Properties getProperties(String bundleName, String fileName) {
        Properties props = new Properties();
        try {/* www .  j a  v  a  2s. com*/
            if (Platform.isRunning()) {
                Bundle bundle = Platform.getBundle(bundleName);
                URL url = bundle.getResource(fileName);
                String filepath = FileLocator.toFileURL(url).getFile();
                props.load(new FileInputStream(new File(filepath)));
            } else {
                props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return props;
    }
}

Related

  1. getManifestInfo()
  2. getMetadataSpecialSymbolsXml()
  3. getPath(final String fileName)
  4. getPath(String resoureLocation)
  5. getProhibitedProxyInterfaces()
  6. getProperty(String propertyName)
  7. getReader(final String name, final String encoding)
  8. getRootPath()
  9. getSimpleName(String fqcn)