问题描述
很抱歉,也许这个问题太傻或者已经回答了,但是我找不到它。
我想知道是否有一些已知的Java类-loader,它能够接受类路径中的远程文件,即CLASSPATH =http://somewhere.net/library.jar:...等条目。
SystemClassLoader
是。您可以尝试,我留给您:
方法方法= URLClassLoader.class.getDeclaredMethod(addURL,new Class [ ] {URL.class});
method.setAccessible(true);
method.invoke(ClassLoader.getSystemClassLoader(),new Object [] {new URL(http://somewhere.net/library.jar)});
Class.forName(your.remote.ClassName);
请告诉我:))
Sorry, maybe this question is too silly or already answered, but I couldn't find it out.
I'm wondering if there is some known Java class-loader that is able to accept remote files in the classpath, i.e., entries like CLASSPATH="http://somewhere.net/library.jar:...".
Note that I am not talking about applets or Java Web Start. Think of an application that can use different back-ends (e.g., MySQL, Oracle), I'd like to prepare the classpath in a shell script, based on the user's back-end preference and have the class-loader to download the needed jar (the jdbc driver in this example) from a distribution server. I'm not talking about Maven either (the user just gets the binary distribution, I don't want to force them to build what they need from the sources).
The SystemClassLoader
is a URLClassLoader
. You could try, I leave it to you:
Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
method.setAccessible(true);
method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{new URL("http://somewhere.net/library.jar")});
Class.forName("your.remote.ClassName");
Let me know :)
这篇关于类路径中的远程jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!