简体   繁体   中英

How can I create a ClassLoader which will use a particular classpath?

在Java中,如何创建将使用特定类路径(可能只是一个jar文件)的ClassLoader?

您创建一个URLClassLoader对象。

Here is a good article on class loading:

http://onjava.com/pub/a/onjava/2005/01/26/classloading.html

Indeed, create a URLClassLoader as pointed out by @bmargulies. It's pretty easy to use, just pass an array of URLs into the constructor.

Maybe also check this thread and, in particular, this post for some tips on how to use Java (hierarchical) ClassLoaders. I don't know what you want to do exactly but you may find it useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM