Example usage for java.lang ClassLoader getSystemClassLoader

List of usage examples for java.lang ClassLoader getSystemClassLoader

Introduction

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

Prototype

@CallerSensitive
public static ClassLoader getSystemClassLoader() 

Source Link

Document

Returns the system class loader.

Usage

From source file:net.sf.janos.util.ui.ImageUtilities.java

/**
 * Loads an image from the provided resource (treated as an absolute, not relative resource)
 * @param resource the image to load/*from  w  ww.  j  a  v  a 2s .  c  o  m*/
 * @return the loaded image
 */
public static ImageData loadImageDataFromSystemClasspath(String resource) {
    InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(resource);
    ImageData data;
    if (is == null) {
        throw new RuntimeException("Resource " + resource + " does not exist: could not load image");
    }
    data = new ImageData(is);
    try {
        is.close();
    } catch (IOException e) {
    }
    return data;
}

From source file:org.lib4j.dbcp.DataSources.java

/**
 * Create a <code>BasicDataSource</code> given a dbcp JAXB binding.
 * <code>ClassLoader.getSystemClassLoader()</code> is used as the <code>driverClassLoader</code> parameter.
 *
 * @param dbcpXml URL of dbcp xml resource.
 * @return the <code>BasicDataSource</code> instance.
 * @throws SAXException If a XML validation error occurs.
 * @throws SQLException If a database access error occurs.
 * @throws IOException If an IO exception occurs.
 *//* w w w.  j av a 2s.com*/
public static BasicDataSource createDataSource(final URL dbcpXml)
        throws IOException, SAXException, SQLException {
    return createDataSource(dbcpXml, ClassLoader.getSystemClassLoader());
}

From source file:com.linkedin.databus2.schemas.ResourceVersionedSchemaSetProvider.java

public ResourceVersionedSchemaSetProvider(ClassLoader classLoader) {
    _classLoader = null != classLoader ? classLoader : ClassLoader.getSystemClassLoader();
}

From source file:org.tamilunicodeconverter.converter.BaminiConverterTest.java

@Test
public void testGetScriptUrl() {
    URL result = baminiConverter.getScriptUrl();
    assertEquals(ClassLoader.getSystemClassLoader().getResource(BaminiConverter.SCRIPT_FILE), result);
    System.out.println("Url: " + result);
}

From source file:co.paralleluniverse.comsat.webactors.servlet.WebActorServletTest.java

@Before
public void setUp() throws Exception {
    this.embeddedServer = cls.newInstance();
    // snippet WebActorInitializer
    WebActorInitializer.setUserClassLoader(ClassLoader.getSystemClassLoader());
    embeddedServer.addServletContextListener(WebActorInitializer.class);
    // end of snippet
    embeddedServer.enableWebsockets();//from www  .  j a  va2  s . c o m
    embeddedServer.start();
    AbstractEmbeddedServer.waitUrlAvailable("http://localhost:8080");
    System.out.println("Server is up");
}

From source file:org.wso2.carbon.integration.test.client.JMSPublisherClient.java

/**
 * This method will publish the data in the test data file to the given topic via ActiveMQ message broker
 *
 * @param topicName             the topic which the messages should be published under
 * @param format                format of the test data file (csv or text)
 * @param testCaseFolderName    Testcase folder name which is in the test artifacts folder
 * @param dataFileName          data file name with the extension to be read
 *
 *//*from   w w  w . j  a  v a2 s.c  o m*/
public static void publish(String topicName, String format, String testCaseFolderName, String dataFileName) {

    if (format == null || "map".equals(format)) {
        format = "csv";
    }

    try {
        Properties properties = new Properties();

        String filePath = getTestDataFileLocation(testCaseFolderName, dataFileName);
        properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties"));
        Context context = new InitialContext(properties);
        TopicConnectionFactory connFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory");
        TopicConnection topicConnection = connFactory.createTopicConnection();
        topicConnection.start();
        Session session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        Topic topic = session.createTopic(topicName);
        MessageProducer producer = session.createProducer(topic);

        List<String> messagesList = readFile(filePath);
        try {

            if (format.equalsIgnoreCase("csv")) {
                log.info("Sending Map messages on '" + topicName + "' topic");
                publishMapMessages(producer, session, messagesList);

            } else {
                log.info("Sending  " + format + " messages on '" + topicName + "' topic");
                publishTextMessage(producer, session, messagesList);
            }
        } catch (JMSException e) {
            log.error("Can not subscribe." + e.getMessage(), e);
        } finally {
            producer.close();
            session.close();
            topicConnection.stop();
            topicConnection.close();
        }
    } catch (Exception e) {
        log.error("Error when publishing messages" + e.getMessage(), e);
    }

    log.info("All Order Messages sent");
}

From source file:org.wso2.siddhi.extension.output.transport.jms.util.JMSClient.java

public void listen() throws InterruptedException {
    Properties properties = new Properties();
    try {//from ww  w. ja  v a  2  s .com
        if ("qpid".equalsIgnoreCase(broker)) {
            properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("qpid.properties"));
        } else if ("activemq".equalsIgnoreCase(broker)) {
            properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties"));
        } else if ("mb".equalsIgnoreCase(broker)) {
            properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mb.properties"));
        } else {
            log.error("Entered broker is invalid! ");
        }
        if (topic != null && topic.isEmpty() || topic.equals("\"\"")) {
            topic = null;
        }
        if (queue != null && queue.isEmpty() || queue.equals("\"\"")) {
            queue = null;
        }
        if (topic == null && queue == null) {
            log.error("Enter topic value or queue value! ");
        } else if (topic != null) {
            Context context = new InitialContext(properties);
            TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) context
                    .lookup("ConnectionFactory");
            TopicConsumer topicConsumer = new TopicConsumer(topicConnectionFactory, topic);
            Thread consumerThread = new Thread(topicConsumer);
            log.info("Starting" + broker + "consumerTopic thread...");
            consumerThread.start();
            Thread.sleep(1 * 60000);
            log.info("Shutting down " + broker + " consumerTopic...");
            topicConsumer.shutdown();
        } else {
            Context context = new InitialContext(properties);
            QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) context
                    .lookup("ConnectionFactory");
            QueueConsumer queueConsumer = new QueueConsumer(queueConnectionFactory, queue);
            Thread consumerThread = new Thread(queueConsumer);
            log.info("Starting" + broker + "consumerQueue thread...");
            consumerThread.start();
            Thread.sleep(1 * 60000);
            log.info("Shutting down " + broker + " consumerQueue...");
            queueConsumer.shutdown();
        }
    } catch (IOException e) {
        log.error("Cannot read properties file from resources. " + e.getMessage(), e);
    } catch (NamingException e) {
        log.error("Invalid properties in the properties " + e.getMessage(), e);
    }
}

From source file:org.apache.ambari.server.stack.StackManagerCommonServicesTest.java

public static StackManager createTestStackManager(String stackRoot, String commonServicesRoot)
        throws Exception {
    try {//  ww w .  j a v  a 2 s . c o  m
        //todo: dao , actionMetaData expectations
        dao = createNiceMock(MetainfoDAO.class);
        actionMetadata = createNiceMock(ActionMetadata.class);
        Configuration config = createNiceMock(Configuration.class);
        expect(config.getSharedResourcesDirPath())
                .andReturn(ClassLoader.getSystemClassLoader().getResource("").getPath()).anyTimes();
        replay(config);
        osFamily = new OsFamily(config);

        replay(dao, actionMetadata);
        StackManager stackManager = new StackManager(new File(stackRoot), new File(commonServicesRoot),
                new StackContext(dao, actionMetadata, osFamily));
        return stackManager;
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:Main.java

/**
 * Changes the locale of the messages.//from   ww  w.j ava2s .c  om
 * 
 * @param locale
 *            Locale the locale to change to.
 * @param resource
 *            the name of the bundle resource
 */
static public ResourceBundle setLocale(final Locale locale, final String resource) {
    try {
        // BEGIN android-removed
        // final ClassLoader loader = VM.bootCallerClassLoader();
        // END android-removed
        return (ResourceBundle) AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Object run() {
                // BEGIN android-changed
                return ResourceBundle.getBundle(resource, locale, ClassLoader.getSystemClassLoader());
                // END android-changed
            }
        });
    } catch (MissingResourceException e) {
    }
    return null;
}

From source file:com.chinamobile.bcbsp.util.ClassLoaderUtil.java

/**
 * Returns the system class loader for delegation.  This is the default
 * delegation parent for new <tt>ClassLoader</tt> instances, and is
 * typically the class loader used to start the application.
 *
 * @return The system class loader for delegation.
 *//*from  w  w w. j av a  2s. c o  m*/
public static ClassLoader getSystemClassLoader() {
    return ClassLoader.getSystemClassLoader();
}