List of usage examples for java.lang ClassLoader getSystemClassLoader
@CallerSensitive public static ClassLoader getSystemClassLoader()
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 queue via ActiveMQ message broker * * @param queueName the queue which the messages should be published under * @param messageFormat messageFormat of the test data file * @param testCaseFolderName Testcase folder name which is in the test artifacts folder * @param dataFileName data file name with the extension to be read * *///ww w . j a v a2 s. c om public static void publishToQueue(String queueName, String messageFormat, String testCaseFolderName, String dataFileName) throws JMSException, IOException, NamingException { //create connection Properties properties = new Properties(); properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties")); Context context = new InitialContext(properties); QueueConnectionFactory connFactory = (QueueConnectionFactory) context.lookup("ConnectionFactory"); QueueConnection queueConnection = connFactory.createQueueConnection(); queueConnection.start(); Session session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(queueName); MessageProducer producer = session.createProducer(queue); //publish data String filePath = getTestDataFileLocation(testCaseFolderName, dataFileName); List<String> messagesList = readFile(filePath); if (messageFormat.equalsIgnoreCase("map")) { publishMapMessages(producer, session, messagesList); } else { publishTextMessage(producer, session, messagesList); } //close connection producer.close(); session.close(); queueConnection.stop(); queueConnection.close(); }
From source file:net.sf.keystore_explorer.gui.CreateApplicationGui.java
/** * Create and show KeyStore Explorer./*w w w. j a v a 2 s .co m*/ */ @Override public void run() { try { if (!checkJreVersion()) { System.exit(1); } initLookAndFeel(applicationSettings); // try to remove crypto restrictions JcePolicyUtil.removeRestrictions(); // if crypto strength still limited, start upgrade assistant if (JcePolicyUtil.isLocalPolicyCrytoStrengthLimited()) { upgradeCryptoStrength(); } final KseFrame kseFrame = new KseFrame(); // workaround to a bug in initializing JEditorPane that seems to be a 1-in-10000 problem if (Thread.currentThread().getContextClassLoader() == null) { Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); } if (OperatingSystem.isMacOs()) { integrateWithMacOs(kseFrame); } kseFrame.display(); // check if stored location of cacerts file still exists checkCaCerts(kseFrame); // open file list passed via command line params (basically same as if files were dropped on application) DroppedFileHandler.openFiles(kseFrame, parameterFiles); // start update check in background (disabled if KSE was packaged as rpm) if (!Boolean.getBoolean(KseFrame.KSE_UPDATE_CHECK_DISABLED)) { checkForUpdates(kseFrame); } } catch (Throwable t) { DError dError = new DError(new JFrame(), t); dError.setLocationRelativeTo(null); dError.setVisible(true); System.exit(1); } finally { closeSplash(); } }
From source file:com.quinsoft.zeidon.utils.JoeUtils.java
/** * Returns an input stream for a resource/filename. Logic will first attempt to find * a filename that matches the resourceName (search is case-insensitive). If a file * is found, the stream is for the file. * * If a file is not found, an attempt is made to find the resource on the classpath. * * @param task - If not null then the ZEIDON_HOME directory will be searched if all * other attempts fail./*from ww w . j a v a2s . co m*/ * @param resourceName - Name of resource to open. * @param classLoader - ClassLoader used to find resources. If null then the system * class loader is used. * * @return the InputStream or null if it wasn't found. */ public static ZeidonInputStream getInputStream(Task task, String resourceName, ClassLoader classLoader) { // If the resourceName contains a '|' then it is a list of resources. We'll return the first // one that is valid. String[] resourceList = PIPE_DELIMITER.split(resourceName); if (resourceList.length > 1) { for (String resource : resourceList) { ZeidonInputStream stream = getInputStream(task, resource.trim(), classLoader); if (stream != null) return stream; } // If we get here then none of the resources in the list were found so return null. return null; } try { // // Default is to assume resourceName is a filename. // File file = getFile(resourceName); if (file.exists()) return ZeidonInputStream.create(file); if (classLoader == null) { if (task != null) classLoader = task.getClass().getClassLoader(); if (classLoader == null) classLoader = new JoeUtils().getClass().getClassLoader(); if (classLoader == null) classLoader = resourceName.getClass().getClassLoader(); if (classLoader == null) classLoader = ClassLoader.getSystemClassLoader(); } // // Try loading as a resource (e.g. from a .jar). // int count = 0; ZeidonInputStream stream = null; URL prevUrl = null; String md5hash = null; for (Enumeration<URL> url = classLoader.getResources(resourceName); url.hasMoreElements();) { URL element = url.nextElement(); if (task != null) task.log().debug("Found resource at " + element); else LOG.debug("--Found resource at " + element); count++; if (count > 1) { // We'll allow duplicate resources if they have the same MD5 hash. if (md5hash == null) md5hash = computeHash(prevUrl); if (!md5hash.equals(computeHash(element))) throw new ZeidonException("Found multiple different resources that match resourceName %s", resourceName); if (task != null) task.log().warn( "Multiple, identical resources found of %s. This usually means your classpath has duplicates", resourceName); else LOG.warn("Multiple, identical resources found of " + resourceName + " This usually means your classpath has duplicates"); } stream = ZeidonInputStream.create(element); prevUrl = element; } if (stream != null) return stream; // // Try loading as a lower-case resource name. // String name = FilenameUtils.getName(resourceName); if (StringUtils.isBlank(name)) return null; String path = FilenameUtils.getPath(resourceName); String newName; if (StringUtils.isBlank(path)) newName = name.toLowerCase(); else newName = path + name.toLowerCase(); stream = ZeidonInputStream.create(classLoader, newName); if (stream != null) return stream; // If task is null then we don't know anything else to try. if (task == null) return null; // // Try loading with ZEIDON_HOME prefix. // newName = task.getObjectEngine().getHomeDirectory() + "/" + resourceName; file = getFile(newName); if (file.exists()) return ZeidonInputStream.create(file); return null; } catch (Exception e) { throw ZeidonException.wrapException(e).prependFilename(resourceName); } }
From source file:com.egreen.tesla.server.api.component.Component.java
public void LoadClass() throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class sysClass = URLClassLoader.class; Method sysMethod = sysClass.getDeclaredMethod("addURL", new Class[] { URL.class }); sysMethod.setAccessible(true);/* www .j ava 2 s . c o m*/ sysMethod.invoke(sysLoader, new Object[] { jarFile }); // for (Object object : classeNames) { // Class classFromName = sysLoader.loadClass(object + ""); // LOGGER.info(classFromName.getSimpleName()); // component.setControllers(object + "", sysClass); // } }
From source file:gov.va.vinci.leo.cr.ExternalCollectionReader.java
/** * Load a resource object from the path to the CollectionReader descriptor then use the framework to initialize the reader. * * @param collectionReaderDescriptor Path to the CollectionReader descriptor. * @throws ResourceInitializationException if there is an error reading the descriptor. * @throws IOException if there is an error in the XML of the descriptor. * @throws InvalidXMLException if the CollectionReader cannot be initialized by the framework. */// ww w .j av a 2 s. c om private void setCollectionReader(String collectionReaderDescriptor) throws IOException, InvalidXMLException, ResourceInitializationException { ClassLoader cl = ClassLoader.getSystemClassLoader(); DefaultResourceLoader loader = new DefaultResourceLoader(cl); Resource resource = loader.getResource(collectionReaderDescriptor); setCollectionReader(resource.getFile()); }
From source file:ws.argo.Responder.Responder.java
private ArrayList<ProbeHandlerPluginIntf> loadHandlerPlugins(ArrayList<AppHandlerConfig> configs) throws IOException, ClassNotFoundException { ClassLoader cl = ClassLoader.getSystemClassLoader(); ArrayList<ProbeHandlerPluginIntf> handlers = new ArrayList<ProbeHandlerPluginIntf>(); for (AppHandlerConfig appConfig : configs) { Class<?> handlerClass = cl.loadClass(appConfig.classname); ProbeHandlerPluginIntf handler;//w w w.ja v a2 s. c om try { handler = (ProbeHandlerPluginIntf) handlerClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { LOGGER.warning( "Could not create an instance of the configured handler class - " + appConfig.classname); LOGGER.warning("Using default handler"); LOGGER.fine("The issue was:"); LOGGER.fine(e.getMessage()); handler = new ConfigFileProbeHandlerPluginImpl(); } handler.setPropertiesFilename(appConfig.configFilename); handlers.add(handler); } return handlers; }
From source file:net.sourceforge.mavenhippo.gen.BeanGeneratorTest.java
@Before public void generate() throws ContentTypeException, FileNotFoundException, IOException, TemplateException { tempFolder = Files.createTempDir(); generatedFolder = new File(tempFolder.getAbsolutePath() + File.separator + "generated"); beansFolder = new File(generatedFolder.getAbsoluteFile() + File.separator + "beans"); if (!generatedFolder.exists() || !generatedFolder.isDirectory()) { generatedFolder.mkdir();//from w w w . ja v a 2 s. c om } if (!beansFolder.exists() || !beansFolder.isDirectory()) { beansFolder.mkdir(); } BeanGenerator beanGenerator = new BeanGenerator(beansOnClassPath, beansInProject, "net.sourceforge.mavenhippo.handlers", new String[] { "generated", "beans" }, namespaces.keySet(), new HashMap<String, ContentTypeBean>(), ClassLoader.getSystemClassLoader()); baseDocument = generateClass(beanGenerator, "basedocument.xml"); testCompound = generateClass(beanGenerator, "TestCompound.xml"); myCompound = generateClass(beanGenerator, "MyCompoundType.xml"); newsDocument = generateClass(beanGenerator, "newsdocumentedited.xml"); // mix-in carouselBannerPickerMixin = generateClass(beanGenerator, "carouselbannerpicker.xml"); //external class test account = generateClass(beanGenerator, "externaltest/account.xml"); accounts = generateClass(beanGenerator, "externaltest/accounts.xml"); }
From source file:org.lib4j.dbcp.DataSources.java
/** * Create a <code>BasicDataSource</code> given a list of dbcp XSB bindings. * <code>ClassLoader.getSystemClassLoader()</code> is used as the <code>driverClassLoader</code> parameter. * * @param dbcp JAXB dbcp binding./*from w ww .ja va2s. c om*/ * @param name The name of the pool to create. (The name is declared in the list of <code>dbcps</code>). * @return the <code>BasicDataSource</code> instance. * @throws SQLException If a database access error occurs. */ public static BasicDataSource createDataSource(final List<Dbcp> dbcps, final String name) throws SQLException { return createDataSource(dbcps, name, ClassLoader.getSystemClassLoader()); }
From source file:org.evosuite.utils.Utils.java
/** * Hack for adding URL with stubs to the ClassPath. Although the stubs path * is on the ClassPath ClassLoader can not load stub class if directory does * not exist during JVM initialization./*www . ja v a 2 s . c o m*/ * * @param path * - path to the folder or jar. * @return true if ClassPath updated successfully. */ public static boolean addURL(String path) { URL url = null; try { url = (new File(path).toURI().toURL()); } catch (MalformedURLException e) { return false; } URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class<URLClassLoader> sysclass = URLClassLoader.class; try { Class<?>[] parameters = new Class[] { URL.class }; Method method = sysclass.getDeclaredMethod("addURL", parameters); method.setAccessible(true); method.invoke(sysloader, new Object[] { url }); method.setAccessible(false); } catch (Throwable t) { return false; } return true; }
From source file:org.mule.module.launcher.DeploymentServiceTestCase.java
@Override protected void doTearDown() throws Exception { // comment out the deletion to analyze results after test is done FileUtils.deleteTree(muleHome);//from w w w. ja va 2 s .c om if (deploymentService != null) { deploymentService.stop(); } super.doTearDown(); // this is a complex classloader setup and we can't reproduce standalone Mule 100%, // so trick the next test method into thinking it's the first run, otherwise // app resets CCL ref to null and breaks the next test Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); }