List of usage examples for java.lang ClassLoader getSystemClassLoader
@CallerSensitive public static ClassLoader getSystemClassLoader()
From source file:com.chaosting.product.hotkey.Main.java
@PostConstruct public void run() { logger.info("Checking the license..."); String licFile = ClassLoader.getSystemClassLoader().getResource("").getPath() + LIC_FILE_NAME; if (!LicenseUtil.isLicValid(licFile)) { logger.info("The license is expired. The software will exit."); return;//from w w w. ja v a 2 s . c o m } logger.info("The license is OK. Checking the required dll..."); String fileName = OSUtil.getOSArch().contains("86") ? "JIntellitype.dll" : "JIntellitype64.dll"; String dllFile = ClassLoader.getSystemClassLoader().getResource("").getPath() + "lib/" + fileName; JIntellitype.setLibraryLocation(dllFile); if (!JIntellitype.isJIntellitypeSupported()) { logger.info("The OS is not Windows or the dll is not found. The software will exit."); return; } JIntellitype jIntellitype = JIntellitype.getInstance(); logger.info("The dll is ready. Parsing the config now..."); final List<Hotkey> hotkeyList = getHotKeyList(); logger.info("Finish parasing config. Registing the hotkey now..."); for (Hotkey hotkey : hotkeyList) { jIntellitype.registerHotKey(hotkey.getIdentifier(), (hotkey.isModShift() == true ? JIntellitype.MOD_SHIFT : 0) + (hotkey.isModControl() == true ? JIntellitype.MOD_CONTROL : 0) + (hotkey.isModWin() == true ? JIntellitype.MOD_WIN : 0) + (hotkey.isModAlt() == true ? JIntellitype.MOD_ALT : 0), (int) hotkey.getKey()); } try { robot = new Robot(); } catch (AWTException e) { e.printStackTrace(); } jIntellitype.addHotKeyListener(new HotkeyListener() { public void onHotKey(int identifier) { for (Hotkey hotkey : hotkeyList) { if (hotkey.getIdentifier() == identifier) { if (hotkey.getGoal().equalsIgnoreCase("exe")) { if (OSUtil.execute(hotkey.getParam())) { logger.info("Executed the " + hotkey.getParam() + " success."); } else { logger.info("Executed the " + hotkey.getParam() + " faild."); } } else if (hotkey.getGoal().equalsIgnoreCase("out")) { int delay = 100; try { delay = Integer.parseInt(properties.getProperty("delay")); } catch (Exception e) { e.printStackTrace(); } robot.delay(delay); for (char c : hotkey.getParam().toCharArray()) { int keycode = convertAsciiInt2KeycodeInt(c); if (keycode == -1) { logger.info("Unsupport character " + c); } else { if ((int) c >= 65 && (int) c <= 90) { robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(keycode); robot.keyRelease(KeyEvent.VK_SHIFT); robot.keyRelease(keycode); } else { robot.keyPress(keycode); robot.keyRelease(keycode); } } } } break; } } } }); logger.info("All the things get ready."); }
From source file:com.eincs.decanter.render.soy.SoyAcre.java
/** * /*from w w w . ja va2 s. co m*/ * @param packageName * @return */ public static SoyAcre forPakckage(String packageName) { final Reflections reflections = new Reflections(new ConfigurationBuilder() .addUrls(ClasspathHelper.forPackage(packageName, ClassLoader.getSystemClassLoader())) .setScanners(new ResourcesScanner())); final Set<String> soyFiles = reflections.getResources(Pattern.compile(SOY_FILE_NAME_PATTERN)); final ClassLoader clazzLoader = ClassLoader.getSystemClassLoader(); return new SoyAcre() { @Override public void addToFileSet(SoyFileSet.Builder fileSetBuilder) { for (String soyFile : soyFiles) { fileSetBuilder.add(clazzLoader.getResource(soyFile)); } } }; }
From source file:org.wso2.carbon.sample.jmsclient.JMSClient.java
public static void publishMessages(String topicName, String broker) { try {/*from ww w .ja va 2 s . c o m*/ // filePath = JMSClientUtil.getEventFilePath(sampleNumber, format, topicName, filePath); TopicConnection topicConnection = null; Session session = null; Properties properties = new Properties(); if (broker.equalsIgnoreCase("activemq")) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties")); Context context = new InitialContext(properties); TopicConnectionFactory connFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory"); topicConnection = connFactory.createTopicConnection(); topicConnection.start(); session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); } else if (broker.equalsIgnoreCase("mb")) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mb.properties")); Context context = new InitialContext(properties); TopicConnectionFactory connFactory = (TopicConnectionFactory) context .lookup("qpidConnectionFactory"); topicConnection = connFactory.createTopicConnection(); topicConnection.start(); session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); } else if (broker.equalsIgnoreCase("qpid")) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("qpid.properties")); Context context = new InitialContext(properties); TopicConnectionFactory connFactory = (TopicConnectionFactory) context .lookup("qpidConnectionFactory"); topicConnection = connFactory.createTopicConnection(); topicConnection.start(); session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); } else { log.info("Please enter a valid JMS message broker. (ex: activemq, mb, qpid"); } if (session != null) { Topic topic = session.createTopic(topicName); MessageProducer producer = session.createProducer(topic); try { List<Map<String, Object>> messageList = new ArrayList<Map<String, Object>>(); Random random = new Random(); for (int j = 0; j < sessionsPerThread; j++) { for (int i = 0; i < msgsPerSession; i++) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("id", random.nextInt() + ""); map.put("value", random.nextInt()); map.put("content", "sample content"); map.put("client", "jmsQueueClient"); // setting the timestamp later messageList.add(map); } publishMapMessage(producer, session, messageList); } } catch (JMSException e) { log.error("Can not subscribe." + e.getMessage(), e); } catch (IOException e) { log.error("Error when reading the data file." + e.getMessage(), e); } finally { producer.close(); session.close(); topicConnection.stop(); } } } catch (Exception e) { log.error("Error when publishing message" + e.getMessage(), e); } }
From source file:net.sourceforge.pmd.lang.java.typeresolution.TypeHelper.java
private static Class<?> loadClass(final ClassLoader nullableClassLoader, final String clazzName) { try {//from w ww. ja va2 s.c om ClassLoader classLoader = nullableClassLoader; if (classLoader == null) { // Using the system classloader then classLoader = ClassLoader.getSystemClassLoader(); } // If the requested type is in the classpath, using the same classloader should work return ClassUtils.getClass(classLoader, clazzName); } catch (ClassNotFoundException ignored) { // The requested type is not on the auxclasspath. This might happen, if the type node // is probed for a specific type (e.g. is is a JUnit5 Test Annotation class). // Failing to resolve clazzName does not necessarily indicate an incomplete auxclasspath. } catch (final LinkageError expected) { // We found the class but it's invalid / incomplete. This may be an incomplete auxclasspath // if it was a NoClassDefFoundError. TODO : Report it? } return null; }
From source file:org.gwtwidgets.server.spring.test.BaseTest.java
protected String readResource(String resource) throws Exception { URL url = getClass().getClassLoader().getResource(resource); if (url == null) url = ClassLoader.getSystemResource(resource); if (url == null) url = ClassLoader.getSystemClassLoader().getResource(resource); URLConnection conn = url.openConnection(); byte[] b = new byte[conn.getContentLength()]; InputStream in = conn.getInputStream(); in.read(b);/* w w w .ja va2 s. c om*/ in.close(); return new String(b, "UTF-8"); }
From source file:com.hangum.tadpole.engine.initialize.JDBCDriverLoader.java
/** * Add jar loader//w ww . j a v a 2 s. c o m * * @param jarArray * @throws Exception */ private static void addJARLoader(Object[] jarArray) throws Exception { URLClassLoader systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); try { Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true); method.invoke(systemClassLoader, jarArray); } catch (Throwable t) { logger.error("jar loader", t); } }
From source file:org.kineticsystem.commons.util.ResourceLoader.java
/** * Return the string representing the content of a resource file specified * by the given path/*from w ww .j a v a 2 s . c om*/ * @param path The resource path i.e * <tt>org/kineticsystem/commons/mymodule/bundle/test.txt</tt>. * @return The resource file content. */ public static String getStreamContent(String path) { StringBuffer buffer = new StringBuffer(); try { InputStream inStream = ClassLoader.getSystemClassLoader().getResourceAsStream(path); InputStreamReader isr = new InputStreamReader(inStream); Reader in = new BufferedReader(isr); int ch; while ((ch = in.read()) > -1) { buffer.append((char) ch); } in.close(); } catch (IOException ex) { logger.fatal(ex); } return buffer.toString(); }
From source file:com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterTest.java
@BeforeClass public static void init() throws Exception { MODEL_XML_TO_CLASSCONVERTER.setBeanClassLoader(ClassLoader.getSystemClassLoader()); for (Class<?> clazz : MODEL_XML_TO_CLASSCONVERTER.convert(Utils.FULL_FIRST_ENTITY_XML_RESOURCE, Utils.FULL_SECOND_ENTITY_XML_RESOURCE, Utils.FULL_THIRD_ENTITY_XML_RESOURCE, Utils.OTHER_FIRST_ENTITY_XML_RESOURCE, Utils.OTHER_SECOND_ENTITY_XML_RESOURCE)) { classes.put(clazz.getCanonicalName(), clazz); }//from w w w . ja va 2 s .c o m for (PropertyDescriptor propertyDescriptor : PropertyUtils.getPropertyDescriptors( classes.get(ClassNameUtils.getFullyQualifiedClassName("full", "firstEntity")))) { propertyDescriptors.put(propertyDescriptor.getName(), propertyDescriptor); } }
From source file:io.trivium.glue.binding.http.StaticResourceHandler.java
@Override public void handle(HttpExchange httpExchange) throws IOException { Session session = new Session(httpExchange); String origURI = httpExchange.getRequestURI().getPath(); String uri = origURI.replace(httpUri, packageUri); ClassLoader cl = ClassLoader.getSystemClassLoader(); InputStream is = cl.getResourceAsStream(uri); if (is != null) { byte[] buf = IOUtils.toByteArray(is); String ending = uri.substring(uri.lastIndexOf('.') + 1); String contentType = MimeTypes.getMimeType(ending, "text/plain"); session.ok(contentType, new String(buf)); return;/*from ww w. j a v a 2s.c o m*/ } //if no response was send so far session.error(404, "resource not found"); }
From source file:org.carewebframework.ui.util.MemoryLeakPreventionUtil.java
/** * CWI-1409//from ww w. j a v a 2s.c o m * <p> * This does what Tomcat 7 context attribute clearReferencesHttpClientKeepAliveThread is * suggested to do but doesn't. Using reflection in this manner is a last resort. * <ul> * <li>JDK 7 is said to fix the keepAliveTimer thread bug.</li> * <li>Tomcat 7.0.x context attribute clearReferencesHttpClientKeepAliveThread is suggested to * fix this leak but does not</li> * </p> */ @SuppressWarnings("restriction") protected static void clearReferencesHttpClientKeepAliveThread() { try { final Field kac = sun.net.www.http.HttpClient.class.getDeclaredField("kac"); kac.setAccessible(true); final Field keepAliveTimer = sun.net.www.http.KeepAliveCache.class.getDeclaredField("keepAliveTimer"); keepAliveTimer.setAccessible(true); final Thread t = (Thread) keepAliveTimer.get(kac.get(null));//kac is a static field, hence null argument if (t != null) {//May not actually be running log.debug("KeepAliveTimer contextClassLoader: " + t.getContextClassLoader()); if (t.getContextClassLoader() == Thread.currentThread().getContextClassLoader()) { t.setContextClassLoader(ClassLoader.getSystemClassLoader()); log.info("Changed KeepAliveTimer classloader to system to prevent leak."); } } } catch (final Exception e) { log.warn( "Exception occurred attempting to prevent sun.net.www.http.HttpClient keepAliveTimer memory leak. Note: this code should not be necessary w/ java7", e); } }