This is done using a new library InetAddressLocator.jar which is NOT added by default to YaCy because it is very old and with that library we will never get a debian package. However, some people want that functionality and it can be made available if the library is taken from http://javainetlocator.sourceforge.net/ and placed into the /lib directory where it will be found using reflection. The new feature will be used to extend the crawler steering. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7975 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
2c3161b4ac
commit
47a8c69745
@ -0,0 +1,45 @@
|
||||
package net.yacy.cora.plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
public class ClassProvider {
|
||||
|
||||
public static Class<?> load(final String classname, final File jarfile) {
|
||||
Class<?> c;
|
||||
try {
|
||||
c = Class.forName(classname);
|
||||
} catch (final ClassNotFoundException e) {
|
||||
c = null;
|
||||
}
|
||||
if (c == null) {
|
||||
// load jar
|
||||
String path = jarfile.getAbsolutePath();
|
||||
if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/');
|
||||
if (!path.startsWith("/")) path = "/" + path;
|
||||
URL[] urls;
|
||||
try {
|
||||
urls = new URL[]{new URL("file", "", path)};
|
||||
final ClassLoader cl = new URLClassLoader(urls);
|
||||
c = cl.loadClass(classname);
|
||||
} catch (final MalformedURLException e) {
|
||||
} catch (final ClassNotFoundException e) {
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Method getStaticMethod(final Class<?> c, final String methodName, final Class<?>[] args) {
|
||||
if (c == null) return null;
|
||||
try {
|
||||
return c.getMethod(methodName, args);
|
||||
} catch (final SecurityException e) {
|
||||
return null;
|
||||
} catch (final NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue