Hello all,
I need an idea how to avoid a NoClassDefFoundError exception.
The trac-plugin has now a dependency to the git-plugin (see
JENKINS-11887) and I want to change it into an optional dependency.
Therefore I changed the pom.xml as described in
https://wiki.jenkins-ci.org/display/JENKINS/Dependencies+among+plugins
(see
https://github.com/GerdZanker/trac-plugin/blob/JENKINS-12588/pom.xml).
The trac-plugin works now as expected, but throws this exception
during runtime if the git-pluin is not installed
Caused by: java.lang.NoClassDefFoundError: hudson/plugins/git/browser/
GitRepositoryBrowser
at java.lang.ClassLoader.defineClass1(Native Method)
...
at java.lang.ClassLoader.loadClass(Unknown Source)
at hudson.plugins.trac.TracGitRepositoryBrowser
$DescriptorImpl.<init>(TracGitRepositoryBrowser.java:97)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
The problem is that I have no idea how to check if the plugin is
installed with "if (Hudson.getInstance().getPlugin("git-plugin") !=
null) { ...".
I can't add the check to the Descriptor (e.g. at
https://github.com/GerdZanker/trac-plugin/blob/JENKINS-12588/src/main/java/hudson/plugins/trac/TracGitRepositoryBrowser.java#L97)
because no code can be placed before the super constructor and the
TracGitRepositoryBrowser is derived from GitRepositoryBrowser which
means that each access to TracGitRepositoryBrowser leads to the
exception.
How do I create the Descriptor only if the git-plugin is installed?
How/when can Descriptors be created? What class and function do I have
to write to place the "if (Hudson.getInstance().getPlugin("git-
plugin") != null) " statement in it?
Does somebody knows code I can use as an example/reference
implementation?
Thanks.
Bye, bye
Gerd