Java Utililty Methods ClassPath Add

List of utility methods to do ClassPath Add

  1. HOME
  2. Java
  3. C
  4. ClassPath Add

Description

The list of methods to do ClassPath Add are organized into topic(s).

Method

void addAllFilesToExtClassLoaderClasspathWithReg(String sDir, String regexpFilter)
Adds all files in a directory to the Ext classloader's classpath
String[] asFilteredFiles = getAllFilesMatchingThisPatternIgnoreCase(sDir, regexpFilter);
for (int i = 0; i < asFilteredFiles.length; i++) {
 String filteredFilePath = new File(sDir, asFilteredFiles[i]).getAbsolutePath();
 addFileToExtClassLoaderClasspath(filteredFilePath);
void addBundleToClassPath(String bundleId)
add Bundle To Class Path
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
if (systemClassLoader instanceof URLClassLoader) {
 URLClassLoader classLoader = (URLClassLoader) systemClassLoader;
 String path = getBundlePath(classLoader, bundleId);
 addFolderToClassPath(classLoader, path);
void addClassPath(File filePath)
Adds the specified file path to the current thread's class loader.
ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader();
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { filePath.toURI().toURL() },
 currentThreadClassLoader);
Thread.currentThread().setContextClassLoader(urlClassLoader);
void addClasspath(String path)
add Classpath
File file = new File(path);
if (file.exists()) {
 URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
 Class<URLClassLoader> urlClass = URLClassLoader.class;
 Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class });
 method.setAccessible(true);
 method.invoke(urlClassLoader, new Object[] { file.toURI().toURL() });
void addClassPath2ClassLoader(ClassLoader cl, String path)
Add specify path to specify loader
try {
 addURL.invoke(cl, new File(path).toURL());
} catch (IllegalArgumentException e) {
 e.printStackTrace();
} catch (MalformedURLException e) {
 e.printStackTrace();
} catch (IllegalAccessException e) {
 e.printStackTrace();
...
void addClasspathEntries(Collection cpEntries)
Add these new classpath entries to resolve against.
List<URL> cp = new ArrayList<URL>();
for (String cpEntry : cpEntries) {
 try {
 cp.add(new File(cpEntry).toURI().toURL());
 } catch (MalformedURLException e) {
URL[] classPath = cp.toArray(new URL[0]);
...
URLClassLoader addClassPathItems(String[] cpItems)
Adds the items to the classPath of the system classLoader
return addClassPathItems(ClassLoader.getSystemClassLoader(), cpItems);
void addDirToClasspath(File directory)
Adds the jars in the given directory to classpath
for (File file : directory.listFiles()) {
 addURL(file.toURI().toURL());
void addDirToClasspath(File directory)
Adds the jars in the given directory to classpath
if (directory.exists()) {
 File[] files = directory.listFiles();
 for (File file : files) {
 addURL(file.toURI().toURL());
void addPathToClassPath(String s)
add Path To Class Path
File f = new File(s);
URL u = f.toURI().toURL();
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class urlClass = URLClassLoader.class;
Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class });
method.setAccessible(true);
method.invoke(urlClassLoader, new Object[] { u });


AltStyle によって変換されたページ (->オリジナル) /