@Test(expected = CommandLineParsingException.class) public void configureNonExistantClassloaderLocation() throws Exception { Main cli = new Main(); cli.classpath = "badClasspathLocation"; cli.configureClassLoader(); }
protected void configureClassLoader() throws CommandLineParsingException { final List<URL> urls = new ArrayList<URL>(); if (this.classpath != null) { String[] classpath; if (isWindows()) { classpath = this.classpath.split(";"); } else { classpath = this.classpath.split(":"); } for (String classpathEntry : classpath) { File classPathFile = new File(classpathEntry); if (!classPathFile.exists()) { throw new CommandLineParsingException(classPathFile.getAbsolutePath() + " does not exist"); } try { if (classpathEntry.endsWith(".war")) { addWarFileClasspathEntries(classPathFile, urls); } else if (classpathEntry.endsWith(".ear")) { JarFile earZip = new JarFile(classPathFile); Enumeration<? extends JarEntry> entries = earZip.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().toLowerCase().endsWith(".jar")) { File jar = extract(earZip, entry); urls.add(new URL("jar:" + jar.toURL() + "!/")); jar.deleteOnExit(); } else if (entry.getName().toLowerCase().endsWith("war")) { File warFile = extract(earZip, entry); addWarFileClasspathEntries(warFile, urls); } } } else { urls.add(new File(classpathEntry).toURL()); } } catch (Exception e) { throw new CommandLineParsingException(e); } } } if (includeSystemClasspath) { classLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader()); } }); } else { classLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls.toArray(new URL[urls.size()])); } }); } ServiceLocator.getInstance().setResourceAccessor(new ClassLoaderResourceAccessor(classLoader)); Thread.currentThread().setContextClassLoader(classLoader); }
Main { protected void configureClassLoader() throws CommandLineParsingException { final List<URL> urls = new ArrayList<URL>(); if (this.classpath != null) { String[] classpath; if (isWindows()) { classpath = this.classpath.split(";"); } else { classpath = this.classpath.split(":"); } for (String classpathEntry : classpath) { File classPathFile = new File(classpathEntry); if (!classPathFile.exists()) { throw new CommandLineParsingException(classPathFile.getAbsolutePath() + " does not exist"); } try { if (classpathEntry.endsWith(".war")) { addWarFileClasspathEntries(classPathFile, urls); } else if (classpathEntry.endsWith(".ear")) { JarFile earZip = new JarFile(classPathFile); Enumeration<? extends JarEntry> entries = earZip.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().toLowerCase().endsWith(".jar")) { File jar = extract(earZip, entry); urls.add(new URL("jar:" + jar.toURL() + "!/")); jar.deleteOnExit(); } else if (entry.getName().toLowerCase().endsWith("war")) { File warFile = extract(earZip, entry); addWarFileClasspathEntries(warFile, urls); } } } else { urls.add(new File(classpathEntry).toURL()); } } catch (Exception e) { throw new CommandLineParsingException(e); } } } if (includeSystemClasspath) { classLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader()); } }); } else { classLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls.toArray(new URL[urls.size()])); } }); } ServiceLocator.getInstance().setResourceAccessor(new ClassLoaderResourceAccessor(classLoader)); Thread.currentThread().setContextClassLoader(classLoader); } }
Main { protected void configureClassLoader() throws CommandLineParsingException { final List<URL> urls = new ArrayList<URL>(); if (this.classpath != null) { String[] classpath; if (isWindows()) { classpath = this.classpath.split(";"); } else { classpath = this.classpath.split(":"); } for (String classpathEntry : classpath) { File classPathFile = new File(classpathEntry); if (!classPathFile.exists()) { throw new CommandLineParsingException(classPathFile.getAbsolutePath() + " does not exist"); } try { if (classpathEntry.endsWith(".war")) { addWarFileClasspathEntries(classPathFile, urls); } else if (classpathEntry.endsWith(".ear")) { JarFile earZip = new JarFile(classPathFile); Enumeration<? extends JarEntry> entries = earZip.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().toLowerCase().endsWith(".jar")) { File jar = extract(earZip, entry); urls.add(new URL("jar:" + jar.toURL() + "!/")); jar.deleteOnExit(); } else if (entry.getName().toLowerCase().endsWith("war")) { File warFile = extract(earZip, entry); addWarFileClasspathEntries(warFile, urls); } } } else { urls.add(new File(classpathEntry).toURL()); } } catch (Exception e) { throw new CommandLineParsingException(e); } } } if (includeSystemClasspath) { classLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader()); } }); } else { classLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls.toArray(new URL[urls.size()])); } }); } ServiceLocator.getInstance().setResourceAccessor(new ClassLoaderResourceAccessor(classLoader)); Thread.currentThread().setContextClassLoader(classLoader); } Main(); }
Main { protected void configureClassLoader() throws CommandLineParsingException { final List<URL> urls = new ArrayList<URL>(); if (this.classpath != null) { String[] classpath; if (isWindows()) { classpath = this.classpath.split(";"); } else { classpath = this.classpath.split(":"); } for (String classpathEntry : classpath) { File classPathFile = new File(classpathEntry); if (!classPathFile.exists()) { throw new CommandLineParsingException(classPathFile.getAbsolutePath() + " does not exist"); } try { if (classpathEntry.endsWith(".war")) { addWarFileClasspathEntries(classPathFile, urls); } else if (classpathEntry.endsWith(".ear")) { JarFile earZip = new JarFile(classPathFile); Enumeration<? extends JarEntry> entries = earZip.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().toLowerCase().endsWith(".jar")) { File jar = extract(earZip, entry); urls.add(new URL("jar:" + jar.toURL() + "!/")); jar.deleteOnExit(); } else if (entry.getName().toLowerCase().endsWith("war")) { File warFile = extract(earZip, entry); addWarFileClasspathEntries(warFile, urls); } } } else { urls.add(new File(classpathEntry).toURL()); } } catch (Exception e) { throw new CommandLineParsingException(e); } } } if (includeSystemClasspath) { classLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader()); } }); } else { classLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls.toArray(new URL[urls.size()])); } }); } ServiceLocator.getInstance().setResourceAccessor(new ClassLoaderResourceAccessor(classLoader)); Thread.currentThread().setContextClassLoader(classLoader); } Main(); static void main(String args[]); boolean isWindows(); }
Main { protected void configureClassLoader() throws CommandLineParsingException { final List<URL> urls = new ArrayList<URL>(); if (this.classpath != null) { String[] classpath; if (isWindows()) { classpath = this.classpath.split(";"); } else { classpath = this.classpath.split(":"); } for (String classpathEntry : classpath) { File classPathFile = new File(classpathEntry); if (!classPathFile.exists()) { throw new CommandLineParsingException(classPathFile.getAbsolutePath() + " does not exist"); } try { if (classpathEntry.endsWith(".war")) { addWarFileClasspathEntries(classPathFile, urls); } else if (classpathEntry.endsWith(".ear")) { JarFile earZip = new JarFile(classPathFile); Enumeration<? extends JarEntry> entries = earZip.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().toLowerCase().endsWith(".jar")) { File jar = extract(earZip, entry); urls.add(new URL("jar:" + jar.toURL() + "!/")); jar.deleteOnExit(); } else if (entry.getName().toLowerCase().endsWith("war")) { File warFile = extract(earZip, entry); addWarFileClasspathEntries(warFile, urls); } } } else { urls.add(new File(classpathEntry).toURL()); } } catch (Exception e) { throw new CommandLineParsingException(e); } } } if (includeSystemClasspath) { classLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader()); } }); } else { classLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls.toArray(new URL[urls.size()])); } }); } ServiceLocator.getInstance().setResourceAccessor(new ClassLoaderResourceAccessor(classLoader)); Thread.currentThread().setContextClassLoader(classLoader); } Main(); static void main(String args[]); boolean isWindows();  }