# Cannot call the class from dynamic library

**URL:** <https://community.jenkins.io/t/cannot-call-the-class-from-dynamic-library/4612>\
**Category:** Ask a question\
**Tags:** question\
**Created:** [November 17, 2022, 2:49pm UTC](https://community.jenkins.io/t/cannot-call-the-class-from-dynamic-library/4612 "2022-11-17T14:49:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![znhv](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/znhv/32/2743_2.png) [@znhv](https://community.jenkins.io/u/znhv)\
**Post date:** [November 17, 2022, 2:49pm UTC](https://community.jenkins.io/t/cannot-call-the-class-from-dynamic-library/4612/1 "2022-11-17T14:49:30Z")

</div>

There is such a structure:

```auto
+- src                    
| +- org
| +- foo
| +- bar.groovy # different classes
+- vars
| +- foo.groovy # declarative pipelines
| +- baz.groovy # initializing pipelines

```

**foo.groovy** :

```auto
#!/usr/bin/env groovy

library retriever: modernSCM([$class: 'GitSCMSource', remote: 'https://linkmygit.com/lib.git']),
        identifier: 'my-lib, changelog: false

import org.foo.*

def test = new Hello()
test.msg()

```

**Bar.groovy** :

```auto
package org.foo

class Hello {
    def test() {
        println("Hello World!")
    }
}

```

The library is downloaded, but the class can’t be called, it says it’s not found. I know this implementation is not suitable for a dynamic library, but I haven’t found any other options. I can’t use @Library(‘my lib’) because the library is in another repository.

Please tell me what other options are available?

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [November 17, 2022, 3:58pm UTC](https://community.jenkins.io/t/cannot-call-the-class-from-dynamic-library/4612/2 "2022-11-17T15:58:28Z")

</div>

> [@znhv](#):
>
> I can’t use @Library(‘my lib’) because the library is in another repository.

do you wan to use the groovy @grab annotation to grab an external jar file?

> [@znhv](#):
>
> ```auto
> library retriever: modernSCM([$class: 'GitSCMSource', remote: 'https://linkmygit.com/lib.git']),
> identifier: 'my-lib, changelog: false
> 
> ```

why do you need to pull in stuff if its part of the structure already?

---

<div class="post-metadata">

**Author:** ![znhv](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/znhv/32/2743_2.png) [@znhv](https://community.jenkins.io/u/znhv)\
**Post date:** [November 17, 2022, 4:21pm UTC](https://community.jenkins.io/t/cannot-call-the-class-from-dynamic-library/4612/3 "2022-11-17T16:21:41Z")

</div>

That’s not so. I am using pipeline script from scm. That is, I load the script from another jenkins space, so I need to load the library.

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [November 17, 2022, 4:37pm UTC](https://community.jenkins.io/t/cannot-call-the-class-from-dynamic-library/4612/4 "2022-11-17T16:37:05Z")

</div>

are you having a library in one pipeline trying to load a library from another pipeline?

I think you should move it all to an external [shared pipeline](https://www.jenkins.io/doc/book/pipeline/shared-libraries/) that both use. I don’t think you can do it this way.

---

<div class="post-metadata">

**Author:** ![znhv](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/znhv/32/2743_2.png) [@znhv](https://community.jenkins.io/u/znhv)\
**Post date:** [November 18, 2022, 6:30am UTC](https://community.jenkins.io/t/cannot-call-the-class-from-dynamic-library/4612/5 "2022-11-18T06:30:59Z")

</div>

Not quite. We have a library that lies in some kind of repository and there are several projects in jenkins. There we create a job, where we indicate that we connect to our repository and take the necessary pipeline from vars. Ideally, we don’t want to store the pipeline in the project repository, but keep everything in one place.

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [November 19, 2022, 12:01am UTC](https://community.jenkins.io/t/cannot-call-the-class-from-dynamic-library/4612/6 "2022-11-19T00:01:58Z")

</div>

So I’ll admit I’m not entirely sure what you are trying to do.

If i do understand you correctly, I still think shared pipelines is the way to go, instead of trying to load things from alternative locations.

For example, for my helm charts, my pipeline is just [buildHelmChart()](https://github.com/halkeye-helm-charts/element-web/blob/0f0386d8925393b792f6af43ac4ae4cd66e21925/Jenkinsfile) which maps to [jenkins-shared-library/buildHelmChart.groovy at f2b30f61541b21f345b4677e29bba647e1e63da7 · halkeye/jenkins-shared-library · GitHub](https://github.com/halkeye/jenkins-shared-library/blob/f2b30f61541b21f345b4677e29bba647e1e63da7/vars/buildHelmChart.groovy)
