Stapler throws strange ClassNotFoundException

已查看 13 次
跳至第一个未读帖子

Ullrich Hafner

未读,
2017年6月6日 16:38:212017/6/6
收件人 Jenkins Developers
I have a strange problem in one of my jelly views. I always get a java.lang.ClassNotFoundException when I want to access the static method of a class:

org.apache.commons.jelly.JellyTagException: jar:file:/Users/hafner/Development/jenkins/plugins/analysis-core/WEB-INF/lib/analysis-core.jar!/hudson/plugins/analysis/core/BuildResult/index.jelly:10:113: <j:invokeStatic> Could not load class: hudson.plugins.analysis.core.GlobalSettings. Reason: java.lang.ClassNotFoundException: hudson.plugins.analysis.core.GlobalSettings at org.apache.commons.jelly.tags.core.InvokeStaticTag.createLoadClassFailedException(InvokeStaticTag.java:177) at org.apache.commons.jelly.tags.core.InvokeStaticTag.doTag(InvokeStaticTag.java:136) at …

The exception is thrown by the following snippet:

<j:invokeStatic var="settings" className="hudson.plugins.analysis.core.GlobalSettings" method="instance“/>

The class exists and it is accessible from another view. Even if I use the invokeStatic on a JDK class then the same exception appears. Has someone an idea what is going on here?

The exception occurs if I place the snippet into the view
https://github.com/jenkinsci/analysis-core-plugin/blob/master/src/main/resources/hudson/plugins/analysis/core/BuildResult/index.jelly

If I place the same piece of code into the following view, then everything works as expected:
https://github.com/jenkinsci/dry-plugin/blob/master/src/main/resources/hudson/plugins/dry/DryTabDetail/dry-details.jelly


signature.asc

Jesse Glick

未读,
2017年6月6日 18:33:442017/6/6
收件人 Jenkins Dev
On Tue, Jun 6, 2017 at 4:38 PM, Ullrich Hafner <ullrich...@gmail.com> wrote:
> java.lang.ClassNotFoundException: hudson.plugins.analysis.core.GlobalSettings
>
> The exception is thrown by the following snippet:
>
> <j:invokeStatic var="settings" className="hudson.plugins.analysis.core.GlobalSettings" method="instance“/>

Unfortunately you cannot use this tag on classes in plugins, only
Jenkins core and its dependencies, I guess since Jenkins fails to
communicate the `uberClassLoader` to Stapler. At least I recall
running into that problem in the past. Instead find some handy `it`,
`instance`, etc. object already in scope and define an instance method
on it to give you whatever object you really need, keeping the logic
in Java code. In this case `DryTabDetail` could have a method

public List<SomeType> getWarnings() {
return DuplicateCode.filter(getAnnotations().getSortedAnnotations());
}

and then you would just need to write

<j:forEach var="warning" items="${it.warnings}">
回复全部
回复作者
转发
0 个新帖子