有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java类加载器应该能够解析和加载来自不同包的类吗?

使用documentation for ClassLoader中给出的示例,我能够加载与${it}位于同一个包中的类:

ClassLoader cl = it.class.getClassLoader()
def builder = cl.loadClass("hudson.plugins.emailext.plugins.ContentBuilder", true).newInstance()

但当我尝试从另一个包加载时,如下所示:

def logParserParser = cl.loadClass("hudson.plugins.logparser.LogParserParser", true).newInstance()

我得到了一个错误:

Exception: javax.script.ScriptException: java.lang.ClassNotFoundException: hudson.plugins.logparser.LogParserParser

如何从不同的包加载类

更新:

我能够解决我的具体问题。如果全班都能解决这个问题,那会好得多。请参阅我对另一个问题的回答here


共 (0) 个答案