service library in Jenkins

28 views
Skip to first unread message

nicolas de loof

unread,
May 18, 2018, 9:03:58 AM5/18/18
to jenkin...@googlegroups.com
Hi there,

I'm writing an extension to jenkins that can't be packaged as a plugin (need to be ran before plugins get loaded) so I created an InitLoader as a Service


@MetaInfServices
public class InitListener implements InitReactorListener {

    @Override
    public void onTaskStarted(Task task) {
        System.out.println("started :" + task.toString());
    }
...
}

When Jenkins starts I get this error =

GRAVE: Failed to initialize Jenkins
hudson.util.HudsonFailedToLoad: java.lang.NoClassDefFoundError: hudson/init/InitReactorListener
at hudson.WebAppMain$3.run(WebAppMain.java:247)
Caused by: java.lang.NoClassDefFoundError: hudson/init/InitReactorListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:560)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:370)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at com.google.common.collect.Lists.newArrayList(Lists.java:139)
at com.google.common.collect.Lists.newArrayList(Lists.java:119)
at jenkins.InitReactorRunner.buildReactorListener(InitReactorRunner.java:63)
at jenkins.InitReactorRunner.run(InitReactorRunner.java:48)
at jenkins.model.Jenkins.executeReactor(Jenkins.java:1096)
at jenkins.model.Jenkins.<init>(Jenkins.java:900)
at hudson.model.Hudson.<init>(Hudson.java:85)
at hudson.model.Hudson.<init>(Hudson.java:81)
at hudson.WebAppMain$3.run(WebAppMain.java:233)


For a reason I can't get, this service when loaded can't access jenkins.war core classes.

I'm running from plain jenkins.war 

java -jar jenkins-2.107.3.war --commonLibFolder=./lib/


Any thoughts ?

Jesse Glick

unread,
May 18, 2018, 12:50:48 PM5/18/18
to Jenkins Dev
On Fri, May 18, 2018 at 9:03 AM, nicolas de loof
<nicolas...@gmail.com> wrote:
> I'm writing an extension to jenkins that can't be packaged as a plugin (need
> to be ran before plugins get loaded)

I think what you are looking for is to use a standard plugin layout
but replacing

<packaging>hpi</packaging>

with

<packaging>jenkins-module</packaging>

and then add it to the list here:

https://github.com/jenkinsci/jenkins/blob/ac749d669d6ba8bd77c0827c8705c9454f973a6a/war/pom.xml#L95-L134

or use `custom-war-packager` to retrofit it into an existing
`jenkins.war` artifact.

(Most of these actually could be converted to regular plugins, I
think; it is only those things which genuinely need to run code before
the Jenkins plugin manager is initialized which must be modules, such
as `ConfidentialStore` implementations.)

nicolas de loof

unread,
May 18, 2018, 12:53:51 PM5/18/18
to jenkin...@googlegroups.com
Thanks for the tip

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr2w9%2BJmfXJh-X63u3smvQstvV6JgGM2T4ML76K%3DXoBZ3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

nicolas de loof

unread,
May 18, 2018, 3:19:52 PM5/18/18
to jenkin...@googlegroups.com
didn't help unfortunately. Still get NoClassDefFoundError: hudson/model/listeners/RunListener

note : I'm not using custom-war-packager, but --commonLibFolder jenkins.war launcher option. Not sure this is commonly used ...

2018-05-18 18:53 GMT+02:00 nicolas de loof <nicolas...@gmail.com>:
Thanks for the tip

Le ven. 18 mai 2018 à 18:50, Jesse Glick <jgl...@cloudbees.com> a écrit :
On Fri, May 18, 2018 at 9:03 AM, nicolas de loof
<nicolas...@gmail.com> wrote:
> I'm writing an extension to jenkins that can't be packaged as a plugin (need
> to be ran before plugins get loaded)

I think what you are looking for is to use a standard plugin layout
but replacing

<packaging>hpi</packaging>

with

<packaging>jenkins-module</packaging>

and then add it to the list here:

https://github.com/jenkinsci/jenkins/blob/ac749d669d6ba8bd77c0827c8705c9454f973a6a/war/pom.xml#L95-L134

or use `custom-war-packager` to retrofit it into an existing
`jenkins.war` artifact.

(Most of these actually could be converted to regular plugins, I
think; it is only those things which genuinely need to run code before
the Jenkins plugin manager is initialized which must be modules, such
as `ConfidentialStore` implementations.)

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.

Jesse Glick

unread,
May 18, 2018, 5:31:23 PM5/18/18
to Jenkins Dev
On Fri, May 18, 2018 at 3:19 PM, nicolas de loof
<nicolas...@gmail.com> wrote:
> I'm not using custom-war-packager, but --commonLibFolder jenkins.war
> launcher option.

Never heard of it, and likely does not work for this purpose. You need
an entry in `jenkins.war!/WEB-INF/lib/*.jar` as I said.

nicolas de loof

unread,
May 19, 2018, 4:09:50 AM5/19/18
to jenkin...@googlegroups.com
right, this option indeed is used to add some jars to the higher level classloader

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages