2

Using the example given in the documentation for ClassLoader I am able to load a class which is in the same package as ${it}:

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

But when I try to load from a different package like this:

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

I get the error:

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

How can I load a class from a different package?

UPDATE:

I was able to make a work around to fix my specific problem. It would be a lot nicer if the class would just resolve. See my answer to another of my questions here.

Community
  • 1
  • 1
ubiquibacon
  • 10,451
  • 28
  • 109
  • 179

2 Answers2

0

It depends on how the ClassLoader has been setup. These type of errors usually occur when the class you want uses a class which is not available. i.e. the class itself is available. What is the exact error message?

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • I updated my question with the exact error. I can navigate to the class with file browser, so I know it is there. The class does its job in Jenkins in a web browser too, I'm just trying to access it so I can get its output without going through a web browser. – ubiquibacon Jan 04 '12 at 16:01
  • You can also get this error if the class previously failed to load e.g. the static block threw an error, however the true cause isn't kept. – Peter Lawrey Jan 04 '12 at 16:06
0

What you attempt should work, I think.

Could it be an issue that the LogParserParser does not have a public no-args constructor?

Also, you might try running your test JVM with -XX:+TraceClassLoading to get better idea on what the classloader attempts to do.

Juha Laiho
  • 596
  • 2
  • 8