List of usage examples for java.net URLClassLoader URLClassLoader
public URLClassLoader(URL[] urls)
From source file:org.mili.core.resource.Mocks.java
/** * Creates the url class loader.//from w ww. j a va 2 s . co m * * @return the uRL class loader * @throws MalformedURLException the malformed url exception */ public URLClassLoader createUrlClassLoader() throws MalformedURLException { return new URLClassLoader(new URL[] { this.root.toURI().toURL() }); }
From source file:org.lnicholls.galleon.gui.Galleon.java
private static void createAndShowGUI() { try {//from ww w . j a v a 2 s . co m System.setProperty("os.user.home", System.getProperty("user.home")); ArrayList errors = new ArrayList(); Server.setup(errors); log = Server.setupLog("org.lnicholls.galleon.gui.Galleon", "GuiTrace", "GuiFile", Constants.GUI_LOG_FILE); // log = Logger.getLogger(Galleon.class.getName()); printSystemProperties(); UIManager.put("ClassLoader", (com.jgoodies.plaf.LookUtils.class).getClassLoader()); UIManager.put("Application.useSystemFontSettings", Boolean.TRUE); Options.setGlobalFontSizeHints(FontSizeHints.MIXED2); Options.setDefaultIconSize(new Dimension(18, 18)); try { UIManager.setLookAndFeel( LookUtils.IS_OS_WINDOWS_XP ? "com.jgoodies.plaf.plastic.PlasticXPLookAndFeel" : Options.getSystemLookAndFeelClassName()); } catch (Exception e) { Tools.logException(Galleon.class, e); } /* * mServerConfiguration = new ServerConfiguration(); if * (mConfigureDir != null) { log.info("Configuration Dir=" + * mConfigureDir.getAbsolutePath()); new * Configurator(mServerConfiguration).load(mAppManager, * mConfigureDir); } else new * Configurator(mServerConfiguration).load(mAppManager); mAddress = * mServerConfiguration.getIPAddress(); if (mAddress == null || * mAddress.length() == 0) mAddress = "127.0.0.1"; */ log.info("Server address: " + mServerAddress); for (int i = 0; i < 100; i++) { try { mRegistry = LocateRegistry.getRegistry(mServerAddress, 1099 + i); String[] names = mRegistry.list(); ServerControl serverControl = (ServerControl) mRegistry.lookup("serverControl"); log.info("Found server at: " + mServerAddress + " on " + (1099 + i)); break; } catch (Throwable ex) { if (log.isDebugEnabled()) Tools.logException(Galleon.class, ex); } } File directory = new File(System.getProperty("apps")); if (!directory.exists() || !directory.isDirectory()) { String message = "App Class Loader directory not found: " + System.getProperty("apps"); InstantiationException exception = new InstantiationException(message); log.error(message, exception); throw exception; } File[] files = directory.listFiles(new FileFilter() { public final boolean accept(File file) { return !file.isDirectory() && !file.isHidden() && file.getName().toLowerCase().endsWith(".jar"); } }); ArrayList urls = new ArrayList(); for (int i = 0; i < files.length; ++i) { try { URL url = files[i].toURI().toURL(); urls.add(url); log.debug(url); } catch (Exception ex) { // should never happen } } directory = new File(System.getProperty("hme")); if (directory.exists()) { files = directory.listFiles(new FileFilter() { public final boolean accept(File file) { return !file.isDirectory() && !file.isHidden() && file.getName().toLowerCase().endsWith(".jar"); } }); for (int i = 0; i < files.length; ++i) { try { URL url = files[i].toURI().toURL(); urls.add(url); log.debug(url); } catch (Exception ex) { // should never happen } } } File currentDirectory = new File("."); directory = new File(currentDirectory.getAbsolutePath() + "/../lib"); // TODO Handle reloading; what if list changes? files = directory.listFiles(new FileFilter() { public final boolean accept(File file) { return !file.isDirectory() && !file.isHidden() && file.getName().toLowerCase().endsWith(".jar"); } }); for (int i = 0; i < files.length; ++i) { try { URL url = files[i].toURI().toURL(); urls.add(url); log.debug(url); } catch (Exception ex) { // should never happen } } URLClassLoader classLoader = new URLClassLoader((URL[]) urls.toArray(new URL[0])); Thread.currentThread().setContextClassLoader(classLoader); mMainFrame = new MainFrame(Tools.getVersion()); splashWindow.setVisible(false); mMainFrame.setVisible(true); /* * javax.swing.SwingUtilities.invokeLater(new Runnable() { public * void run() { mToGo.getRecordings(); } }); */ if (!isCurrentVersion()) { if (JOptionPane.showConfirmDialog(mMainFrame, "A new version of Galleon is available. Do you want to download the latest version?", "New Version", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { try { BrowserLauncher.openURL("http://galleon.tv"); } catch (Exception ex) { Tools.logException(Galleon.class, ex); } } } } catch (Exception ex) { Tools.logException(Galleon.class, ex); System.exit(0); } }
From source file:org.apache.pulsar.functions.utils.Utils.java
/** * Load a jar//from www . j a va 2 s .c o m * @param jar file of jar * @return classloader * @throws MalformedURLException */ public static ClassLoader loadJar(File jar) throws MalformedURLException { java.net.URL url = jar.toURI().toURL(); return new URLClassLoader(new URL[] { url }); }
From source file:org.kles.m3.M3ClassLoader.java
public M3ClassLoader(M3ClassPathEntry[] classPath) { super();//from w w w. ja va 2s . c om this.m_classPaths = new ArrayList(); for (M3ClassPathEntry entry : classPath) { this.m_classPaths.add(entry.getPath().toFile()); } this.m_zipProblems = new HashSet(); this.m_pathProblems = new HashSet(); urlclassLoader = new URLClassLoader(createURLList(classPath)); MetaDataDef defSrc = getMetaDataDef(urlclassLoader, "OCUSMA"); }
From source file:org.kles.m3.M3ClassLoader.java
private void DBTest() throws MalformedURLException { ClassLoader loaderSpe = new URLClassLoader(createURLList(listSpe)); ClassLoader loaderStd = new URLClassLoader(createURLList(listStd)); MetaDataDef defSrc = getMetaDataDef(loaderSpe, "OCUSMA"); MetaDataDef defStd = getMetaDataDef(loaderStd, "OCUSMA"); }
From source file:io.fabric8.forge.ipaas.repository.NexusConnectionRepository.java
private static String loadCamelConnectorJSonSchema(URL url) { try {/* www . j av a2s. c om*/ // is it a JAR file URLClassLoader child = new URLClassLoader(new URL[] { url }); InputStream is = child.getResourceAsStream("camel-connector.json"); if (is != null) { return loadText(is); } IOHelpers.close(is); } catch (Throwable e) { e.printStackTrace(); // ignore } return null; }
From source file:org.apache.blur.command.BaseCommandManager.java
protected void loadNewCommand(FileSystem fileSystem, FileStatus fileStatus, BigInteger hashOfContents) throws IOException { File file = new File(_tmpPath, UUID.randomUUID().toString()); if (!file.mkdirs()) { LOG.error("Error while trying to create a tmp directory for loading a new command set from [{0}].", fileStatus.getPath());//from w ww .j a v a 2 s .c o m return; } LOG.info("Copying new command with hash [{2}] set from [{0}] into [{1}].", fileStatus.getPath(), file.getAbsolutePath(), hashOfContents.toString(Character.MAX_RADIX)); copyLocal(fileSystem, fileStatus, file); URLClassLoader loader = new URLClassLoader(getUrls(file).toArray(new URL[] {})); Enumeration<URL> resources = loader.getResources(META_INF_SERVICES_ORG_APACHE_BLUR_COMMAND_COMMANDS); loadCommandClasses(resources, loader, hashOfContents); }
From source file:com.informatica.um.binge.api.impl.PluginsFactory.java
/** * Load the plugin class and return the native and java dependencies for the plugin * @param pluginClass//from w w w . j a va2 s .co m * @param deps * @return * @throws MalformedURLException * @throws ClassNotFoundException */ private Class loadPluginClass(String pluginClass, Multimap<String, File> deps, File pluginFolder) throws MalformedURLException, ClassNotFoundException { URL[] jars = new URL[deps.get(LIB).size()]; int i = 0; for (File file : deps.get(LIB)) { LOG.info("Loading jar file {}", file.getAbsolutePath()); jars[i++] = file.toURI().toURL(); } // Create URL class loader and load the class file return new URLClassLoader(jars).loadClass(pluginClass); }
From source file:org.colombbus.tangara.Configuration.java
/** * Gets the urlClassLoader that enables to access to the objects jar files. * * @return an URLClassLoader/*from www . java 2 s. c o m*/ */ public URLClassLoader getObjectsClassLoader() { if (objectsClassLoader == null) { try { if (isExecutionMode()) { URL[] listUrl = new URL[1]; listUrl[0] = instance.getTangaraPath().toURI().toURL(); objectsClassLoader = new URLClassLoader(listUrl); } else { File f = new File(instance.getTangaraPath().getParentFile(), "objects"); File[] list = f.listFiles(); Vector<URL> vector = new Vector<URL>(); for (int i = 0; i < list.length; i++) { if (list[i].getName().endsWith(".jar")) vector.add(list[i].toURI().toURL()); } File flib = new File( instance.getTangaraPath().getParentFile().getAbsolutePath().replace("\\", "/") + "/objects/lib"); File[] listflib = flib.listFiles(); for (int j = 0; j < listflib.length; j++) { if (listflib[j].getName().endsWith(".jar")) vector.add(listflib[j].toURI().toURL()); } URL[] listUrl = new URL[vector.size()]; for (int j = 0; j < vector.size(); j++) listUrl[j] = vector.get(j); objectsClassLoader = new URLClassLoader(listUrl); } } catch (Exception e1) { displayError("URL MAL FORMED " + e1); return null; } } return objectsClassLoader; }
From source file:com.globalsight.ling.tm3.tools.TM3Command.java
private ClassLoader getClassLoader(Properties props) { String classpath = props.getProperty(TM3_CLASSPATH_PROPERTY); if (classpath == null) { return getClass().getClassLoader(); }//from w w w .j av a 2 s . c o m List<URL> urls = new ArrayList<URL>(); String cpSep = System.getProperty("path.separator"); try { String[] cps = classpath.split(cpSep); for (String cp : cps) { File f = new File(cp); if (!f.exists()) { System.err.println("Skipping non-existent classpath element " + f); continue; } if (cp.toLowerCase().endsWith(".jar")) { StringBuilder sb = new StringBuilder("jar:").append(f.toURI().toString()).append("!/"); urls.add(new URL(sb.toString())); } else if (f.isDirectory()) { urls.add(f.toURI().toURL()); } else { System.err.println("Not a directory or JAR file: " + f); } } } catch (IOException e) { System.err.println("Could not load from " + classpath + ": " + e.getMessage()); } return new URLClassLoader(urls.toArray(new URL[urls.size()])); }