Example usage for java.lang ClassLoader getSystemResource

List of usage examples for java.lang ClassLoader getSystemResource

Introduction

In this page you can find the example usage for java.lang ClassLoader getSystemResource.

Prototype

public static URL getSystemResource(String name) 

Source Link

Document

Find a resource of the specified name from the search path used to load classes.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    Properties props = new Properties();
    URL url = ClassLoader.getSystemResource("props.properties");
    props.load(url.openStream());//from w  w  w  . j a va 2  s .c o  m
    System.out.println("prop1 :\n " + props.get("prop1"));
    System.out.println("prop2 :\n " + props.get("prop2"));
}

From source file:Main.java

public static void main(String[] a) throws Exception {
    Properties p = new Properties();
    URL url = ClassLoader.getSystemResource("/com/java2s/config/system.props");
    if (url != null)
        p.load(url.openStream());/*from   w  ww. j a v  a2 s  .  c o m*/

}

From source file:Main.java

public static void main(String args[]) throws Exception {

    Properties props = new Properties();
    URL url = ClassLoader.getSystemResource("myprops.props");
    props.load(url.openStream());/* w w w.  j a  v a  2s.c  o m*/
    System.out.println(props);

}

From source file:Main.java

  public static void main(String args[]) throws Exception {
  Properties props = new Properties();
  URL url = ClassLoader.getSystemResource("props.properties");
  props.load(url.openStream());/* ww  w .j a v a  2  s  .  co  m*/
  System.out.println("prop1 :\n " + props.get("prop1"));
  System.out.println("prop2 :\n " + props.get("prop2"));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame frame = new JFrame();
    JEditorPane edPane = new JEditorPane();
    edPane.setContentType("text/html");

    HTMLEditorKit hek = new HTMLEditorKit();

    edPane.setEditorKit(hek);/*ww  w.j a v a 2 s.  co  m*/

    HTMLDocument doc = (HTMLDocument) edPane.getDocument();

    doc.insertString(0, "Test testing", null);

    Element[] roots = doc.getRootElements();
    Element body = null;
    for (int i = 0; i < roots[0].getElementCount(); i++) {
        Element element = roots[0].getElement(i);
        if (element.getAttributes().getAttribute(StyleConstants.NameAttribute) == HTML.Tag.BODY) {
            body = element;
            break;
        }
    }

    doc.insertAfterEnd(body, "<img src=" + ClassLoader.getSystemResource("thumbnail.png").toString() + ">");
    frame.add(edPane);

    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:weather.WeatherByCityCountry.java

/**
 * //  w  ww. j ava  2 s  .c  o m
 * 
 * @param args
 * @throws IOException
 * @throws MalformedURLException
 */
public static void main(String[] args) throws MalformedURLException, IOException {
    Properties properties = new Properties();
    properties.load(ClassLoader.getSystemResource("config.properties").openStream());
    String appId = properties.getProperty("openweathermap.apikey");
    if (args.length == 0) {

        getWeatherDataByCityNCountry(appId, "London", "uk");

    } else {
        for (int i = 0; i < args.length; i += 2) {
            getWeatherDataByCityNCountry(appId, args[i], args[i + 1]);
        }
    }

}

From source file:org.firstopen.singularity.devicemgr.emulators.EmulatorManager.java

/**
 * @param args//from w w  w.  ja v  a  2s . c o m
 * @throws Exception 
 */
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {

    XMLConfiguration config;
    try {
        URL url = ClassLoader.getSystemResource("emulation.xml");

        config = new XMLConfiguration(url);

        Object obj = config.getProperty("emulatons.emulator.class");
        Collection<String> classes = null;
        if (obj instanceof Collection) {
            classes = (Collection<String>) obj;
        } else
            throw new ClassNotFoundException("property is not of type Collection");

        Thread[] threads = new Thread[50];
        int i = 0;
        for (String className : classes) {

            List<String> portList = (List<String>) config.getList("emulations.emulator(" + i + ").ports");
            Class c = Class.forName(className);

            log.info("Shutdown manager registered...");
            ShutdownManager sdm = new ShutdownManager();
            Runtime.getRuntime().addShutdownHook(sdm);

            Class partypes[] = new Class[1];
            partypes[0] = String.class;
            Constructor ct = c.getConstructor(partypes);
            for (String port : portList) {
                Object arglist[] = new Object[1];
                arglist[0] = new Integer(37);
                arglist[1] = new Integer(47);
                Object emulator = ct.newInstance(arglist);

                ShutdownManager.addManagedObject((Shutdown) emulator);
                threads[i] = new Thread((Runnable) emulator);
                threads[i].start();

            } // end for all ports

            i++;
        } // end for all emulators
        for (Thread thread : threads) {
            thread.join();
        }
    } catch (Exception e) {

        throw e;
    }
}

From source file:org.dd4t.databind.DD4TModelConverter.java

public static void main(String[] args)
        throws IOException, XMLStreamException, SerializationException, URISyntaxException {

    // Load Spring
    context = new ClassPathXmlApplicationContext("application-context.xml");
    String homepage = FileUtils.readFileToString(new File(ClassLoader.getSystemResource("test.json").toURI()));
    deserializeJson(homepage);// w  w w .  j a  va  2  s. c o m

}

From source file:org.jbpm.designer.stencilset.Beautifier.java

/**
 * @param args//from  www.ja va  2  s  .  c  o  m
 * @throws java.io.IOException
 */
public static void main(String[] args) throws IOException {

    // assertions and beautifier instantiation.
    assert (args.length != 0);

    // get the stencil set and beautifier scripts.
    String stencilsetScript = "set = " + getScriptFromFile(args[0]);
    String beautifierScript = getScriptFromFile(
            ClassLoader.getSystemResource("org/oryxeditor/stencilset/beautifier.js").getFile());

    // java script runtime initialization
    Context cx = Context.enter();
    cx.setOptimizationLevel(-1);

    try {

        ScriptableObject scope = new ImporterTopLevel(cx);

        // evaluate stencil set and beautifier
        cx.evaluateString(scope, stencilsetScript, "<cmd>", 1, null);
        cx.evaluateString(scope, beautifierScript, "<cmd>", 1, null);

        // run beautifier on stencil set
        String result = (String) ScriptableObject.callMethod(scope, "beautify",
                new Object[] { scope.get("set", scope) });

        System.out.println(result.toString());
    } finally {
        Context.exit();
    }
}

From source file:org.pentaho.pac.server.StopJettyServer.java

public static void main(String[] args) {
    FileInputStream fis = null;//from   ww w  .j  a v a  2s  . c o m
    Properties properties = null;
    try {
        URL url = ClassLoader.getSystemResource(DEFAULT_CONSOLE_PROPERTIES_FILE_NAME);
        URI uri = url.toURI();
        File file = new File(uri);
        fis = new FileInputStream(file);
    } catch (Exception e1) {
        logger.error(Messages.getErrorString("StopJettyServer.ERROR_0001_OPEN_PROPS_FAILED", //$NON-NLS-1$
                DEFAULT_CONSOLE_PROPERTIES_FILE_NAME));
    }
    if (null != fis) {
        properties = new Properties();
        try {
            properties.load(fis);
        } catch (IOException e) {
            logger.error(Messages.getErrorString("StopJettyServer.ERROR_0002_LOAD_PROPS_FAILED", //$NON-NLS-1$
                    DEFAULT_CONSOLE_PROPERTIES_FILE_NAME));
        }
    }
    if (properties != null) {
        String stopPortNumber = properties.getProperty(STOP_PORT, null);

        if (stopPortNumber != null && stopPortNumber.length() > 0) {
            stopPort = Integer.parseInt(stopPortNumber);
        } else {
            stopPort = DEFAULT_STOP_PORT_NUMBER;
        }
    } else {
        stopPort = DEFAULT_STOP_PORT_NUMBER;
    }
    InetAddress host = null;
    String hostName = null;
    ;
    try {
        host = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        hostName = DEFAULT_HOSTNAME;
    }

    try {
        Socket clientSocket = null;
        // If you were not able to find the host name we will default to localhost
        if (hostName != null && hostName.length() > 0) {
            clientSocket = new Socket(hostName, stopPort);
        } else {
            clientSocket = new Socket(host, stopPort);
        }
        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
        out.println(STOP_ARG);
        out.flush();
    } catch (Exception e) {
        logger.error(Messages.getErrorString("StopJettyServer.ERROR_0003_UNKNOWN_HOST", host.getHostName())); //$NON-NLS-1$
    }

}