本文整理汇总了Java中java.net.URLClassLoader.getURLs方法的典型用法代码示例。如果您正苦于以下问题:Java URLClassLoader.getURLs方法的具体用法?Java URLClassLoader.getURLs怎么用?Java URLClassLoader.getURLs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URLClassLoader
的用法示例。
在下文中一共展示了URLClassLoader.getURLs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassPathEntries
import java.net.URLClassLoader; //导入方法依赖的package包/类
private Collection<URI> getClassPathEntries(ClassLoader classLoader) {
Collection<URI> entries = new LinkedHashSet<>();
// Search parent first, since it's the order ClassLoader#loadClass() uses.
ClassLoader parent = classLoader.getParent();
if (parent != null) {
entries.addAll(getClassPathEntries(parent));
}
if (classLoader instanceof URLClassLoader) {
URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
for (URL entry : urlClassLoader.getURLs()) {
try {
entries.add(entry.toURI());
} catch (URISyntaxException e) {
throw ThrowableUtil.propagate(e);
}
}
}
return new LinkedHashSet<>(entries);
}
示例2: findJars
import java.net.URLClassLoader; //导入方法依赖的package包/类
public static Set<String> findJars(ClassLoader classLoader) {
Set<String> ret = new HashSet<>();
if (classLoader instanceof URLClassLoader && !excludeClassLoader.contains(classLoader.getClass().getName())) {
URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
URL[] urLs = urlClassLoader.getURLs();
for (URL url : urLs) {
String s = url.toString();
if (s.startsWith("file:") && !isExculed(s)) {// URL对象是抽象的,可能不是本地文件,可能是一个目录,这里就不讨论如何处理了
ret.add(url.getPath());
}
}
}
ClassLoader parent = classLoader.getParent();
if (parent != null) {
ret.addAll(findJars(parent));
}
return ret;
}
示例3: JdkCompiler
import java.net.URLClassLoader; //导入方法依赖的package包/类
public JdkCompiler(){
options = new ArrayList<String>();
options.add("-target");
options.add("1.6");
StandardJavaFileManager manager = compiler.getStandardFileManager(diagnosticCollector, null, null);
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader instanceof URLClassLoader
&& (! loader.getClass().getName().equals("sun.misc.Launcher$AppClassLoader"))) {
try {
URLClassLoader urlClassLoader = (URLClassLoader) loader;
List<File> files = new ArrayList<File>();
for (URL url : urlClassLoader.getURLs()) {
files.add(new File(url.getFile()));
}
manager.setLocation(StandardLocation.CLASS_PATH, files);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoaderImpl>() {
public ClassLoaderImpl run() {
return new ClassLoaderImpl(loader);
}
});
javaFileManager = new JavaFileManagerImpl(manager, classLoader);
}
示例4: getClassPathEntries
import java.net.URLClassLoader; //导入方法依赖的package包/类
@VisibleForTesting
static ImmutableMap<File, ClassLoader> getClassPathEntries(ClassLoader classloader) {
LinkedHashMap<File, ClassLoader> entries = Maps.newLinkedHashMap();
// Search parent first, since it's the order ClassLoader#loadClass() uses.
ClassLoader parent = classloader.getParent();
if (parent != null) {
entries.putAll(getClassPathEntries(parent));
}
if (classloader instanceof URLClassLoader) {
URLClassLoader urlClassLoader = (URLClassLoader) classloader;
for (URL entry : urlClassLoader.getURLs()) {
if (entry.getProtocol().equals("file")) {
File file = toFile(entry);
if (!entries.containsKey(file)) {
entries.put(file, classloader);
}
}
}
}
return ImmutableMap.copyOf(entries);
}
示例5: loadandrunclass
import java.net.URLClassLoader; //导入方法依赖的package包/类
static void loadandrunclass(String classname) throws Exception {
Class<?> cl = Class.forName(classname);
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());
Class<?> c = loader.loadClass(classname);
Runnable r = (Runnable) c.newInstance();
r.run();
}
示例6: loadAndRunClass
import java.net.URLClassLoader; //导入方法依赖的package包/类
static void loadAndRunClass(String classname) throws Exception {
Class cl = Class.forName(classname);
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());
Class c = loader.loadClass(classname);
Runnable r = (Runnable) c.newInstance();
r.run();
}
示例7: findJars
import java.net.URLClassLoader; //导入方法依赖的package包/类
private static void findJars(Set<String> set, ClassLoader classLoader) {
try {
if (classLoader instanceof URLClassLoader) {
URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
URL[] urLs = urlClassLoader.getURLs();
String JAVA_HOME = new File(System.getProperty("java.home"), "..").getCanonicalPath();
for (URL url : urLs) {
String path = url.getPath();
path = URLDecoder.decode(path, Const.DEFAULT_ENCODING);
// path : /d:/xxx
if (path.startsWith("/") && path.indexOf(":") == 2) {
path = path.substring(1);
}
if (!path.toLowerCase().endsWith(".jar")) {
initByFilePath(new File(path).getCanonicalPath());
}
if (!path.startsWith(JAVA_HOME) && !isExcludeJar(path)) {
set.add(url.getPath());
}
}
}
ClassLoader parent = classLoader.getParent();
if (parent != null) {
findJars(set, parent);
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
示例8: doTestClassUnloading
import java.net.URLClassLoader; //导入方法依赖的package包/类
/**
* Loads {@link WillBeUnloadedException} in a separate {@code ClassLoader}, calls {@code
* getChecked(future, WillBeUnloadedException.class)}, and returns the loader. The caller can then
* test that the {@code ClassLoader} can still be GCed. The test amounts to a test that {@code
* getChecked} holds no strong references to the class.
*/
private WeakReference<?> doTestClassUnloading() throws Exception {
URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader();
URLClassLoader shadowLoader = new URLClassLoader(myLoader.getURLs(), null);
@SuppressWarnings("unchecked")
Class<WillBeUnloadedException> shadowClass =
(Class<WillBeUnloadedException>)
Class.forName(WillBeUnloadedException.class.getName(), false, shadowLoader);
assertNotSame(shadowClass, WillBeUnloadedException.class);
getChecked(immediateFuture("foo"), shadowClass);
return new WeakReference<ClassLoader>(shadowLoader);
}
示例9: listClasses
import java.net.URLClassLoader; //导入方法依赖的package包/类
private void listClasses(URLClassLoader loader) {
URL[] urls = loader.getURLs();
for (final URL url : urls) {
log.info("Listing classes for URL {}", url);
listClasses(loader, url);
}
}
开发者ID:PacktPublishing,项目名称:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming,代码行数:8,代码来源:ClassLister.java
示例10: JdkCompileTask
import java.net.URLClassLoader; //导入方法依赖的package包/类
public JdkCompileTask(JdkCompilerClassLoader classLoader, Iterable<String> options){
compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
throw new IllegalStateException("Cannot find the system Java compiler. "
+ "Check that your class path includes tools.jar");
}
this.classLoader = classLoader;
ClassLoader loader = classLoader.getParent();
diagnostics = new DiagnosticCollector<JavaFileObject>();
final StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
if (loader instanceof URLClassLoader
&& (!loader.getClass().getName().equalsIgnoreCase("sun.misc.Launcher$AppClassLoader"))) {
try {
@SuppressWarnings("resource")
URLClassLoader urlClassLoader = (URLClassLoader) loader;
List<File> path = new ArrayList<File>();
for (URL url : urlClassLoader.getURLs()) {
File file = new File(url.getFile());
path.add(file);
}
fileManager.setLocation(StandardLocation.CLASS_PATH, path);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
javaFileManager = new JavaFileManagerImpl(fileManager, classLoader);
this.options = new ArrayList<String>();
if (options != null) { // make a save copy of input options
for (String option : options) {
this.options.add(option);
}
}
}
示例11: inClassPath
import java.net.URLClassLoader; //导入方法依赖的package包/类
@PublicAPI(usage = ACCESS)
public static Set<Location> inClassPath() {
Set<Location> result = new HashSet<>();
for (URLClassLoader loader : findAllUrlClassLoadersInContext()) {
for (URL url : loader.getURLs()) {
result.add(Location.of(url));
}
}
return result;
}
示例12: main
import java.net.URLClassLoader; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
Class cl = Class.forName("Test6805724");
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
// Iterate over all 2^k-1 divisors.
for (int k = 1; k < Long.SIZE; k++) {
long divisor = (1L << k) - 1;
System.setProperty("divisor", "" + divisor);
ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());
Class c = loader.loadClass("Test6805724");
Runnable r = (Runnable) c.newInstance();
r.run();
}
}
示例13: getPluginUrl
import java.net.URLClassLoader; //导入方法依赖的package包/类
public URL getPluginUrl() {
// add this plugin itself to the runtime classpath to make integration available
URLClassLoader classLoader = (URLClassLoader) getClass().getClassLoader();
for (URL gradleClassUrl : classLoader.getURLs()) {
if (gradleClassUrl.getFile().contains("crnk-gen-typescript")) {
return gradleClassUrl;
}
}
throw new IllegalStateException("crnk-gen-typescript.jar not found in gradle build classpath");
}
示例14: loadJMH
import java.net.URLClassLoader; //导入方法依赖的package包/类
public static void loadJMH() {
URLClassLoader classLoader = (URLClassLoader) All.class.getClassLoader();
StringBuilder classpath = new StringBuilder();
for(URL url : classLoader.getURLs())
classpath.append(url.getPath()).append(File.pathSeparator);
System.setProperty("java.class.path", classpath.toString());
}
示例15: LapisClassLoader
import java.net.URLClassLoader; //导入方法依赖的package包/类
public LapisClassLoader(URLClassLoader parent){
super(parent.getURLs(), parent);
// TransformerAsmPoll.register(this);
}