use of java.net.URLClassLoader in project ats-framework by Axway.
the class ClasspathUtils method loadJarsFromClasspath.
/**
* This method detects and add any JAR to loadedJarsMap
*/
private void loadJarsFromClasspath() {
loadedJarsMap.clear();
ClassLoader classLoader = getClass().getClassLoader();
URL[] urls = null;
do {
//check if the class loader is instance of URL and cast it
if (classLoader instanceof URLClassLoader) {
urls = ((URLClassLoader) classLoader).getURLs();
} else {
// if the ClassLoader is not instance of URLClassLoader we will break the cycle and log a message
log.info("ClassLoader " + classLoader + " is not instance of URLClassLoader, so it will skip it.");
// if the ClassLoader is from JBoss, it is instance of BaseClassLoader,
// we can take the ClassPath from a public method -> listResourceCache(), from JBoss-classloader.jar
// this ClassLoader is empty, we will get the parent
classLoader = classLoader.getParent();
continue;
}
try {
loadJarsFromManifestFile(classLoader);
} catch (IOException ioe) {
log.warn("MANIFEST.MF is loaded, so we will not search for duplicated jars!");
}
// add all jars from ClassPath to the map
for (int i = 0; i < urls.length; i++) {
addJarToMap(urls[i].getFile());
}
// get the parent classLoader
classLoader = classLoader.getParent();
} while (classLoader != null);
if (loadedJarsMap.isEmpty()) {
// jars are not found, so probably no URL ClassLoaders are found
throw new RuntimeException("Most probrably specific server is used without URLClassLoader instances!");
}
}
use of java.net.URLClassLoader in project intellij-community by JetBrains.
the class SceneBuilderImpl method updateCustomLibrary.
private void updateCustomLibrary() {
final URLClassLoader oldClassLoader = myClassLoader;
myClassLoader = createProjectContentClassLoader(myProject);
FXMLLoader.setDefaultClassLoader(myClassLoader);
if (oldClassLoader != null) {
try {
oldClassLoader.close();
} catch (IOException e) {
LOG.info(e);
}
}
final Collection<CustomComponent> customComponents = DumbService.getInstance(myProject).runReadActionInSmartMode(this::collectCustomComponents);
try {
final CustomLibrary customLibrary = new CustomLibrary(myClassLoader, customComponents);
myEditorController.setLibrary(customLibrary);
myCustomComponents = customComponents;
} catch (Exception e) {
LOG.info(e);
}
}
use of java.net.URLClassLoader in project intellij-community by JetBrains.
the class JavaFxInjectPageLanguageIntention method composeUserClassLoader.
private static ClassLoader composeUserClassLoader(Project project) {
final List<URL> urls = new ArrayList<>();
final List<String> list = OrderEnumerator.orderEntries(project).recursively().librariesOnly().runtimeOnly().getPathsList().getPathList();
for (String path : list) {
try {
urls.add(new File(FileUtil.toSystemIndependentName(path)).toURI().toURL());
} catch (MalformedURLException e1) {
LOG.info(e1);
}
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]));
}
use of java.net.URLClassLoader in project intellij-community by JetBrains.
the class SnapShooter method main.
public static void main(String[] args) throws Throwable {
int origClassPathSize = Integer.parseInt(args[0]);
int port = Integer.parseInt(args[1]);
ClassLoader loader = SnapShooter.class.getClassLoader();
if (loader instanceof URLClassLoader) {
URLClassLoader ucl = (URLClassLoader) loader;
URL[] oldURLs = ucl.getURLs();
URL[] newURLs = new URL[origClassPathSize];
final int startIndex = oldURLs.length - origClassPathSize;
System.arraycopy(oldURLs, startIndex, newURLs, 0, origClassPathSize);
loader = new URLClassLoader(newURLs, null);
Thread.currentThread().setContextClassLoader(loader);
}
final Thread thread = new Thread(new SnapShooterDaemon(port), "snapshooter");
thread.setDaemon(true);
thread.start();
String mainClass = args[2];
String[] parms = new String[args.length - 3];
for (int j = 3; j < args.length; j++) {
parms[j - 3] = args[j];
}
Method m = loader.loadClass(mainClass).getMethod("main", parms.getClass());
try {
ensureAccess(m);
m.invoke(null, (Object) parms);
} catch (InvocationTargetException ite) {
throw ite.getTargetException();
}
}
use of java.net.URLClassLoader in project nhin-d by DirectProject.
the class JamesLoader method main.
@SuppressWarnings("deprecation")
public static void main(String[] args) {
try {
File fl = new File("testfile");
int idx = fl.getAbsolutePath().lastIndexOf("testfile");
String path = fl.getAbsolutePath().substring(0, idx);
String phoenixHome = path + "src/test/resources/james-server/";
ArrayList<URL> classLoaderURLList = new ArrayList<URL>();
System.setProperty("phoenix.home", phoenixHome);
classLoaderURLList.add(new File(phoenixHome + "bin/phoenix-loader.jar").toURL());
URL[] classLoaderURLArray = classLoaderURLList.toArray(new URL[classLoaderURLList.size()]);
//System.setProperty( "catalina.home", "C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5");
URLClassLoader childClassLoader = new URLClassLoader(classLoaderURLArray, JamesLoader.class.getClassLoader());
final Class<?> mainClass = childClassLoader.loadClass("org.apache.avalon.phoenix.launcher.Main");
final Class<?>[] paramTypes = new Class[] { args.getClass() };
final Method method = mainClass.getMethod("main", paramTypes);
Object main_instance = mainClass.newInstance();
method.invoke(main_instance, new Object[] { args });
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations