List of usage examples for java.lang ClassLoader getSystemClassLoader
@CallerSensitive public static ClassLoader getSystemClassLoader()
From source file:com.phoenixnap.oss.ramlapisync.plugin.SpringMvcEndpointGeneratorMojo.java
private String getSchemaLocation() { if (StringUtils.hasText(schemaLocation)) { if (!schemaLocation.contains(":")) { String resolvedPath = project.getBasedir().getAbsolutePath(); if (resolvedPath.endsWith(File.separator) || resolvedPath.endsWith("/")) { resolvedPath = resolvedPath.substring(0, resolvedPath.length() - 1); }/*from w w w .jav a 2 s . c om*/ if (!schemaLocation.startsWith(File.separator) && !schemaLocation.startsWith("/")) { resolvedPath += File.separator; } resolvedPath += schemaLocation; if (!schemaLocation.endsWith(File.separator) && !schemaLocation.endsWith("/")) { resolvedPath += File.separator; } resolvedPath = resolvedPath.replace(File.separator, "/").replace("\\", "/"); try { URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class<?> urlClass = URLClassLoader.class; Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true); method.invoke(urlClassLoader, new Object[] { new File(resolvedPath).toURI().toURL() }); return "classpath:/"; // since we have added this folder to the classpath this // should be used by the plugin } catch (Exception ex) { this.getLog().error("Could not add schema location to classpath", ex); return new File(resolvedPath).toURI().toString(); } } return schemaLocation; } return null; }
From source file:org.ireland.jnetty.webapp.WebApp.java
void displayClassLoader() { log.debug("BootstrapClassLoader : "); URL[] urls = sun.misc.Launcher.getBootstrapClassPath().getURLs(); for (URL url : urls) log.debug(url);/*from w w w. ja v a 2 s .co m*/ log.debug("----------------------------"); // ? URLClassLoader extClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader().getParent(); log.debug(extClassLoader); log.debug(" : "); urls = extClassLoader.getURLs(); for (URL url : urls) log.debug(url); log.debug("----------------------------"); // ?() URLClassLoader appClassLoader = (URLClassLoader) _classLoader.getParent(); log.debug(appClassLoader); log.debug("() : "); urls = appClassLoader.getURLs(); for (URL url : urls) log.debug(url); log.debug("----------------------------"); // ?() appClassLoader = (URLClassLoader) _classLoader; log.debug(appClassLoader); log.debug("() : "); urls = appClassLoader.getURLs(); for (URL url : urls) log.debug(url); log.debug("----------------------------"); }
From source file:org.mycontroller.standalone.StartApp.java
public static boolean loadInitialProperties(String propertiesFile) { try {/*w ww .j av a 2 s . c o m*/ Properties properties = new Properties(); if (propertiesFile == null) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mycontroller.properties")); } else { FileReader fileReader = new FileReader(propertiesFile); properties.load(fileReader); fileReader.close(); } AppProperties.getInstance().loadProperties(properties); _logger.debug("Properties are loaded successfuly..."); return true; } catch (IOException ex) { _logger.error("Exception while loading properties file, ", ex); return false; } }
From source file:org.wikimedia.analytics.varnishkafka.Cli.java
private Integer writeAvroOutput() { Schema schema = null;/* w ww. j a va 2 s. c o m*/ int n = 0; try { InputStream inputStream = ClassLoader.getSystemClassLoader() .getResourceAsStream("WebRequest.avro.json"); schema = new Schema.Parser().parse(inputStream); inputStream.close(); File file = new File(cwd.getPath(), "test." + getFormat()); log.info("Output file path: " + file.toString()); file.delete(); DatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(schema); DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<GenericRecord>(writer); if (compress) { dataFileWriter.setCodec(CodecFactory.snappyCodec()); } dataFileWriter.create(schema, file); try { LineIterator it = FileUtils.lineIterator(inputFile, "UTF-8"); try { setStart(System.nanoTime()); while (it.hasNext()) { n++; String line = it.nextLine(); String[] fields = line.split("\\t"); // Populate data GenericRecord r = new GenericData.Record(schema); r.put("kafka_offset", Long.parseLong(fields[0])); r.put("host", fields[1]); r.put("seq_num", Long.parseLong(fields[2])); r.put("timestamp", fields[3]); r.put("response", Float.parseFloat(fields[4])); r.put("ip", fields[5]); r.put("http_status", fields[6]); r.put("bytes_sent", parseBytesSent(fields[7])); r.put("request_method", fields[8]); r.put("uri", fields[9]); r.put("proxy_host", fields[10]); r.put("mime_type", fields[11]); r.put("referer", fields[12]); r.put("x_forwarded_for", fields[13]); r.put("user_agent", fields[14]); r.put("accept_language", fields[15]); r.put("x_analytics", fields[16]); dataFileWriter.append(r); } setEnd(System.nanoTime()); } finally { dataFileWriter.flush(); dataFileWriter.close(); } } catch (IOException ex) { ex.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } return n; }
From source file:edu.stanford.epad.common.plugins.impl.ClassFinderTestUtils.java
public static String printClasspath() { StringBuilder sb = new StringBuilder(); try {//from www. java 2 s .c om ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); URL[] urls = ((URLClassLoader) systemClassLoader).getURLs(); for (URL url : urls) { sb.append(url.getFile()).append("\n"); } } catch (Exception e) { logger.warning("printClasspath failed for: ", e); } return sb.toString(); }
From source file:kieker.tools.bridge.cli.CLIServerMain.java
/** * Interpret command line type option./*from w w w . j a v a 2 s . co m*/ * * @param lookupEntityMap * the map for ids to Kieker records * * @return a reference to an ServiceContainer * @throws CLIConfigurationErrorException * if an error occured in setting up a connector or if an unknown service connector was specified * @throws ConnectorDataTransmissionException */ private static IServiceConnector createService(final Configuration configuration, final ConcurrentMap<Integer, LookupEntity> lookupEntityMap) throws CLIConfigurationErrorException, ConnectorDataTransmissionException { try { return CLIServerMain.createConnector( ClassLoader.getSystemClassLoader().loadClass(configuration.getStringProperty(CLI_CONNECTOR)), configuration, lookupEntityMap); } catch (final ClassNotFoundException e) { throw new CLIConfigurationErrorException( "Specified bridge connector " + configuration.getStringProperty(CLI_CONNECTOR) + " not found.", e); } }
From source file:org.apache.hadoop.hbase.io.crypto.Encryption.java
private static ClassLoader getClassLoaderForClass(Class<?> c) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = c.getClassLoader();/* w ww . ja va 2 s .co m*/ } if (cl == null) { cl = ClassLoader.getSystemClassLoader(); } if (cl == null) { throw new RuntimeException("A ClassLoader to load the Cipher could not be determined"); } return cl; }
From source file:com.web.server.SARDeployer.java
/** * This method extracts the SAR archive and configures for the SAR and starts the services * @param file// w ww. j av a 2s . c o m * @param warDirectoryPath * @throws IOException */ public void extractSar(File file, String warDirectoryPath) throws IOException { ZipFile zip = new ZipFile(file); ZipEntry ze = null; String fileName = file.getName(); fileName = fileName.substring(0, fileName.indexOf('.')); fileName += "sar"; String fileDirectory; CopyOnWriteArrayList classPath = new CopyOnWriteArrayList(); Enumeration<? extends ZipEntry> entries = zip.entries(); int numBytes; while (entries.hasMoreElements()) { ze = entries.nextElement(); // //System.out.println("Unzipping " + ze.getName()); String filePath = deployDirectory + "/" + fileName + "/" + ze.getName(); if (!ze.isDirectory()) { fileDirectory = filePath.substring(0, filePath.lastIndexOf('/')); } else { fileDirectory = filePath; } // //System.out.println(fileDirectory); createDirectory(fileDirectory); if (!ze.isDirectory()) { FileOutputStream fout = new FileOutputStream(filePath); byte[] inputbyt = new byte[8192]; InputStream istream = zip.getInputStream(ze); while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) { fout.write(inputbyt, 0, numBytes); } fout.close(); istream.close(); if (ze.getName().endsWith(".jar")) { classPath.add(filePath); } } } zip.close(); URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = loader.getURLs(); WebClassLoader sarClassLoader = new WebClassLoader(urls); for (int index = 0; index < classPath.size(); index++) { System.out.println("file:" + classPath.get(index)); new WebServer().addURL(new URL("file:" + classPath.get(index)), sarClassLoader); } new WebServer().addURL(new URL("file:" + deployDirectory + "/" + fileName + "/"), sarClassLoader); sarsMap.put(fileName, sarClassLoader); System.out.println(sarClassLoader.geturlS()); try { Sar sar = (Sar) sardigester.parse(new InputSource( new FileInputStream(deployDirectory + "/" + fileName + "/META-INF/" + "mbean-service.xml"))); CopyOnWriteArrayList mbeans = sar.getMbean(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); System.out.println(mbs); ObjectName objName; for (int index = 0; index < mbeans.size(); index++) { Mbean mbean = (Mbean) mbeans.get(index); System.out.println(mbean.getObjectname()); System.out.println(mbean.getCls()); objName = new ObjectName(mbean.getObjectname()); Class helloWorldService = sarClassLoader.loadClass(mbean.getCls()); Object obj = helloWorldService.newInstance(); if (mbs.isRegistered(objName)) { mbs.invoke(objName, "stopService", null, null); //mbs.invoke(objName, "destroy", null, null); mbs.unregisterMBean(objName); } mbs.registerMBean(obj, objName); CopyOnWriteArrayList attrlist = mbean.getMbeanAttribute(); if (attrlist != null) { for (int count = 0; count < attrlist.size(); count++) { MBeanAttribute attr = (MBeanAttribute) attrlist.get(count); Attribute mbeanattribute = new Attribute(attr.getName(), attr.getValue()); mbs.setAttribute(objName, mbeanattribute); } } mbs.invoke(objName, "startService", null, null); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedObjectNameException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstanceAlreadyExistsException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MBeanRegistrationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NotCompliantMBeanException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstanceNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ReflectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MBeanException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidAttributeValueException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AttributeNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.codehaus.mojo.antlr.AbstractAntlrMojo.java
private void executeAntlrInIsolatedClassLoader(String[] args, Artifact antlrArtifact) throws MojoExecutionException { try {//from www . j a va 2s. co m URLClassLoader classLoader = new URLClassLoader(new URL[] { antlrArtifact.getFile().toURL() }, ClassLoader.getSystemClassLoader()); Class toolClass = classLoader.loadClass("antlr.Tool"); toolClass.getMethod("main", new Class[] { String[].class }).invoke(null, new Object[] { args }); } catch (MalformedURLException e) { throw new MojoExecutionException("Unable to resolve antlr:antlr artifact url", e); } catch (ClassNotFoundException e) { throw new MojoExecutionException("could not locate antlr.Tool class"); } catch (NoSuchMethodException e) { throw new MojoExecutionException("error locating antlt.Tool#main", e); } catch (InvocationTargetException e) { throw new MojoExecutionException("error perforing antlt.Tool#main", e.getTargetException()); } catch (IllegalAccessException e) { throw new MojoExecutionException("error perforing antlt.Tool#main", e); } }
From source file:org.springframework.data.hadoop.mapreduce.ExecutionUtils.java
static void earlyLeaseDaemonInit(Configuration config) throws IOException { ClassLoader cl = config.getClassLoader(); if (cl instanceof ParentLastURLClassLoader) { if (log.isDebugEnabled()) { log.debug("Preventing DFS LeaseDaemon TCCL leak"); }/*w w w . j ava 2 s . co m*/ FileSystem fs = FileSystem.get(config); Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); Path p = new Path("/tmp/shdp-lease-early-init-" + UUID.randomUUID().toString()); // create/delete fs.create(p).close(); fs.delete(p, false); } }