How to use methods from a global external java library in a Groovy Jenkins Pipeline?
<p>First, I´m new to Java, Groovy and Jenkins so please be patient with me ;)</p>

<p>I´m preparing a Jenkins server with Pipeline support for future use in our build environment.
We use a special inhouse scripting language for which i have to write a wrapper in java. There is no option to do the work only in Groovy, we have to use this special language.</p>

<p>I have tried many methods of referencing the java lib to this jenkins project but neither worked. 
Mainly i´ve used the documentation on <a href="https://github.com/jenkinsci/workflow-cps-global-lib-plugin" rel="nofollow noreferrer">https://github.com/jenkinsci/workflow-cps-global-lib-plugin</a> to implement this but also tried several approaches searching google or stackoverflow. Following the documentation, this include should be possible.</p>

<p>I´ve reduced the process to a test setup for testing purposes.</p>

<p>Assume the following...</p>

<p>I have a multibranch project in Jenkins named 'MultibranchTestProject01'.<br>
The Jenkinsfile:</p>

<pre><code>@Library('DeltaJenkinsScripts@develop')

def runStageCollect = true

if (runStageCollect)
{
    stage("Collect")
    {
        helloWorld("Joe")
    }
}
</code></pre>

<p>The referenced library is referenced globally via 'Global Pipeline Libraries' in the Jenkins settings but also explicitly here to clarify things.
It´s hosted in a git environment and the referencing seems to work.
The file structure of this library:</p>

<p>/vars/helloWorld.groovy</p>

<pre><code>package de.dcomp.prod

def call(name) {
    def tt = new Test()
    tt.testText()
}
</code></pre>

<p>/src/de/dcomp/prod/Test.groovy</p>

<pre><code>package de.dcomp.prod

import de.dcomp.ftel.*

def testText()
{
    def sRetVal = ""
    echo "testText - START"
    //sRetVal = ScriptRunner.GetStaticSampleText()
    def oSR = new ScriptRunner()
    sRetVal = oSR.GetInstanceSampleText()
    echo "ReturnValue: ${sRetVal}"
}
</code></pre>

<p>I have a java lib called ScriptRunner-0.0.1-SNAPSHOT.jar. This library has a single class:</p>

<pre><code>package de.dcomp.ftel;

public class ScriptRunner
{
    public String GetInstanceSampleText()
    {
        return "ScriptRunner.GetInstanceSampleText() called...";
    }
    public static String GetStaticSampleText()
    {
        return "ScriptRunner.GetStaticSampleText() called...";
    }
}
</code></pre>

<p>I have no problem in referencing and using this library in a standalone java project.</p>

<p>I´ve tried several ways to include it:  </p>

<ul>
<li>Put the jar file to 'C:\Users\cr.groovy\lib'</li>
<li>Setting the Classpath in a testing linux environment.</li>
<li>Using the plugin "Pipeline: Classpath Steps" to add the library to the classpath in different notations, e.g. 'C:\Users\cr.groovy\lib',  C:/Users/cr/.groovy/lib', 'C:\Users\cr.groovy\lib\ScriptRunner-0.0.1-SNAPSHOT.jar', 'C:/Users/cr/.groovy/lib/ScriptRunner-0.0.1-SNAPSHOT.jar', 'file:///C:/Users/cr/.groovy/lib/ScriptRunner-0.0.1-SNAPSHOT.jar'</li>
<li>adding the lib to a local maven repository and referencing per @GrabResolver and @Grab, though this is not the solution i would like to have</li>
</ul>

<p>or dynamic loading with:</p>

<pre><code>this.class.classLoader.rootLoader.addURL(new URL("file:///C:/Users/cr/.groovy/lib/ScriptRunner-0.0.1-SNAPSHOT.jar"));
def srClass = Class.forName("de.dcomp.ftel.ScriptRunner")
def sr = srClass.newInstance()
</code></pre>

<p>The result is always something like this.</p>

<pre><code>groovy.lang.MissingPropertyException: No such property: ScriptRunner for class: de.dcomp.prod.Test
</code></pre>

<p>or this:</p>

<pre><code>de/dcomp/prod/Test.groovy: 10: unable to resolve class ScriptRunner 
 @ line 10, column 12.
    def oSR = new ScriptRunner()
</code></pre>

<p>The error messages point always in the direction that the process cannot find the Java library. The same thing happened if i try to use some other library, e.g. from Apache Commons.</p>

<p>I would like to avoid writig it as a plugin if this is possible.</p>

<p>Thanks in advance!</p>