本文整理了Java中java.net.URLClassLoader.getURLs()
方法的一些代码示例,展示了URLClassLoader.getURLs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URLClassLoader.getURLs()
方法的具体详情如下:
包路径:java.net.URLClassLoader
类名称:URLClassLoader
方法名:getURLs
[英]Returns the search list of this URLClassLoader.
[中]返回此URLClassLoader的搜索列表。
代码示例来源:origin: wildfly/wildfly
public static String getClasspathString() {
StringBuffer classpath = new StringBuffer();
ClassLoader applicationClassLoader = VersionImpl.class.getClassLoader();
URL[] urls = ((URLClassLoader) applicationClassLoader).getURLs();
for (URL url : urls) {
classpath.append(url.getFile()).append("\r\n");
}
return classpath.toString();
}
代码示例来源:origin: apache/incubator-dubbo
public JdkCompiler() {
options = new ArrayList<String>();
options.add("-source");
options.add("1.6");
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>() {
@Override
public ClassLoaderImpl run() {
return new ClassLoaderImpl(loader);
}
});
javaFileManager = new JavaFileManagerImpl(manager, classLoader);
}
代码示例来源:origin: jmxtrans/jmxtrans
private String getCurrentClasspath() {
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)cl).getURLs();
return Joiner.on(File.pathSeparator)
.join(
from(asList(urls))
.transform(new Function<URL, String>() {
@Nullable
@Override
public String apply(URL input) {
try {
return new File(input.toURI()).getPath();
} catch(URISyntaxException e) {
return input.getPath();
}
}
}));
}
代码示例来源:origin: h2oai/h2o-2
public VM(String[] java, String[] args) {
_args = new ArrayList<String>();
_args.add(System.getProperty("java.home") + "/bin/java");
// Iterate on URIs in case jar has been unpacked by Boot
_args.add("-cp");
String cp = "";
for( URL url : ((URLClassLoader) ClassLoader.getSystemClassLoader()).getURLs() ) {
try {
cp += new File(new URI(url.toString())) + File.pathSeparator;
} catch( URISyntaxException e ) {
throw Log.errRTExcept(e);
}
}
_args.add(cp);
_args.addAll(Arrays.asList(java));
if( args != null )
_args.addAll(Arrays.asList(args));
}
代码示例来源:origin: apache/incubator-dubbo
public JdkCompiler() {
options = new ArrayList<String>();
options.add("-source");
options.add("1.6");
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>() {
@Override
public ClassLoaderImpl run() {
return new ClassLoaderImpl(loader);
}
});
javaFileManager = new JavaFileManagerImpl(manager, classLoader);
}
代码示例来源:origin: HotswapProjects/HotswapAgent
private static URL archivePathToURLViaURLClassLoader(URLClassLoader urlClassLoader, String archivePath) {
URL[] urls = urlClassLoader.getURLs();
if (urls != null) {
for (URL url: urls) {
String fileName = url.getFile();
String checkedArchivePath = (fileName.endsWith("/") && !archivePath.endsWith("/")) ? (archivePath + "/") : archivePath;
if (fileName.endsWith(checkedArchivePath)) {
return archiveFilePathToURL(fileName);
}
}
}
return null;
}
代码示例来源:origin: redisson/redisson
URL[] urls = ((URLClassLoader) classLoader).getURLs();
for (URL u : urls) {
File f = FileUtil.toFile(u);
String[] bootstrapFiles = StringUtil.splitc(bootstrap, File.pathSeparatorChar);
for (String bootstrapFile: bootstrapFiles) {
File f = new File(bootstrapFile);
if (f.exists()) {
try {
代码示例来源:origin: apache/kylin
static File[] extractRoots(ClassLoader loader, boolean recursive) {
List<ClassLoader> loaders = new ArrayList<>();
while (loader != null) {
loaders.add(loader);
if (!recursive)
break;
loader = loader.getParent();
}
List<File> roots = new ArrayList();
// parent first
for (int i = loaders.size() - 1; i >= 0; i--) {
ClassLoader l = loaders.get(i);
if (l instanceof URLClassLoader) {
for (URL url : ((URLClassLoader) l).getURLs()) {
// tricky: space is "%20" in URL
File f = new File(url.getFile().replace("%20", " "));
roots.add(f);
}
}
}
return (File[]) roots.toArray(new File[roots.size()]);
}
代码示例来源:origin: HotswapProjects/HotswapAgent
private static URL archivePathToURLViaURLClassLoader(URLClassLoader urlClassLoader, String archivePath) {
URL[] urls = urlClassLoader.getURLs();
if (urls != null) {
for (URL url: urls) {
String fileName = url.getFile();
String checkedArchivePath = (fileName.endsWith("/") && !archivePath.endsWith("/")) ? (archivePath + "/") : archivePath;
if (fileName.endsWith(checkedArchivePath)) {
return archiveFilePathToURL(fileName);
}
}
}
return null;
}
代码示例来源:origin: eclipse-vertx/vert.x
if (extraClasspath != null) {
for (String pathElement: extraClasspath) {
File file = new File(pathElement);
try {
URL url = file.toURI().toURL();
urls.addAll(Arrays.asList(urlc.getURLs()));
代码示例来源:origin: ltsopensource/light-task-scheduler
URLClassLoader urlClassLoader = (URLClassLoader) loader;
List<File> files = new ArrayList<File>();
for (URL url : urlClassLoader.getURLs()) {
files.add(new File(url.getFile()));
代码示例来源:origin: uber/NullAway
private void processClassPath() {
URL[] classLoaderUrls =
((URLClassLoader) Thread.currentThread().getContextClassLoader()).getURLs();
for (URL url : classLoaderUrls) {
String path = url.getFile();
if (path.matches(config.getJarInferRegexStripModelJarName())) {
String name = path.replaceAll(config.getJarInferRegexStripModelJarName(), "$1");
LOG(DEBUG, "DEBUG", "model jar name: " + name + "\tjar path: " + path);
if (!mapModelJarLocations.containsKey(name))
mapModelJarLocations.put(name, new LinkedHashSet<>());
mapModelJarLocations.get(name).add(path);
}
}
}
代码示例来源:origin: rapidoid/rapidoid
public static synchronized Set<String> getClasspath() {
if (CLASSPATH.isEmpty()) {
String classpathProp = System.getProperty("java.class.path");
if (classpathProp != null) {
String[] classpathEntries = classpathProp.split(File.pathSeparator);
for (String cpe : classpathEntries) {
cpe = Str.trimr(cpe, '/');
CLASSPATH.add(new File(cpe).getAbsolutePath());
}
}
ClassLoader cl = ClassLoader.getSystemClassLoader();
if (cl instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) cl).getURLs();
for (URL url : urls) {
String path = URIs.urlDecode(Str.trimr(url.getPath(), '/'));
CLASSPATH.add(new File(path).getAbsolutePath());
}
}
if (U.isEmpty(appJar)) {
inferAppJarFromClasspath();
}
}
return CLASSPATH;
}
代码示例来源:origin: alibaba/yugong
private JavaFileManagerImpl buildFileManager(JdkCompilerClassLoader classLoader, ClassLoader loader,
DiagnosticCollector<JavaFileObject> diagnostics) {
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
if (loader instanceof URLClassLoader
&& (!"sun.misc.Launcher$AppClassLoader".equalsIgnoreCase(loader.getClass().getName()))) {
try {
URLClassLoader urlClassLoader = (URLClassLoader) loader;
List<File> paths = new ArrayList<File>();
for (URL url : urlClassLoader.getURLs()) {
File file = new File(url.getFile());
paths.add(file);
}
fileManager.setLocation(StandardLocation.CLASS_PATH, paths);
} catch (Throwable e) {
throw new YuGongException(e);
}
}
return new JavaFileManagerImpl(fileManager, classLoader);
}
代码示例来源:origin: scouter-project/scouter
URL[] urls = u.getURLs();
for(int i = 0; urls!=null && i<urls.length ; i++){
try {
cp.appendClassPath(urls[i].getFile());
} catch (NotFoundException e) {
Logger.println("S229", "[Error]" + e.getMessage());
代码示例来源:origin: org.codehaus.groovy/groovy
if (target == null) target = new File(".");
while (cl != null) {
if (cl instanceof URLClassLoader) {
for (URL u : ((URLClassLoader) cl).getURLs()) {
try {
paths.add(new File(u.toURI()).getPath());
} catch (URISyntaxException e) {
paths.add(new File(codeSource.getLocation().toURI()).getPath());
代码示例来源:origin: ltsopensource/light-task-scheduler
URLClassLoader urlClassLoader = (URLClassLoader) loader;
List<File> files = new ArrayList<File>();
for (URL url : urlClassLoader.getURLs()) {
files.add(new File(url.getFile()));
代码示例来源:origin: scouter-project/scouter
URL[] urls = u.getURLs();
for(int i = 0; urls!=null && i<urls.length ; i++){
cp.appendClassPath(urls[i].getFile());
} catch (NotFoundException e) {
Logger.println("S219", "[Error]" + e.getMessage());
代码示例来源:origin: apache/incubator-druid
@Test
public void test06GetClassLoaderForExtension() throws IOException
{
final File some_extension_dir = temporaryFolder.newFolder();
final File a_jar = new File(some_extension_dir, "a.jar");
final File b_jar = new File(some_extension_dir, "b.jar");
final File c_jar = new File(some_extension_dir, "c.jar");
a_jar.createNewFile();
b_jar.createNewFile();
c_jar.createNewFile();
final URLClassLoader loader = Initialization.getClassLoaderForExtension(some_extension_dir, false);
final URL[] expectedURLs = new URL[]{a_jar.toURI().toURL(), b_jar.toURI().toURL(), c_jar.toURI().toURL()};
final URL[] actualURLs = loader.getURLs();
Arrays.sort(actualURLs, Comparator.comparing(URL::getPath));
Assert.assertArrayEquals(expectedURLs, actualURLs);
}
代码示例来源:origin: jOOQ/jOOR
for (URL url : ((URLClassLoader) cl).getURLs()) {
if (classpath.length() > 0)
classpath.append(separator);
classpath.append(new File(url.getFile()));
内容来源于网络,如有侵权,请联系作者删除!