getResource not working when plugin is installed in Jenkins

316 views
Skip to first unread message

Daniel Anechitoaie

unread,
Jul 12, 2018, 10:39:43 AM7/12/18
to Jenkins Developers
Hi,

I'm using getClass().getClassLoader().getResource("plugins") to load a resource.
This works well when I run the plugin with mvn hpi:run but fails to work when I run the plugin from jenkins (mvn clean install & manually upload the hpi file in Jenkins > Plugins > Advanced)

I've tried to print the places the classLoader looks for resources and when I run from Jenkins I get:
file:/var/cache/jenkins/war/WEB-INF/classes/

but when I run locally with mvn:hpi run I get:
file:/Users/daniels/Work/osf-builder-suite-standalone-sonar-linter-plugin/src/main/resources/
file:/Users/daniels/Work/osf-builder-suite-standalone-sonar-linter-plugin/target/classes/
file:/Users/daniels/Work/osf-builder-suite-standalone-sonar-linter-plugin/target/tmp/webapp/WEB-INF/classes/


Any idea how I could use getResource so that it works when plugin runs/is installed normally in Jenkins also?

Jesse Glick

unread,
Jul 12, 2018, 1:11:19 PM7/12/18
to Jenkins Dev
On Thu, Jul 12, 2018 at 10:39 AM Daniel Anechitoaie
<danie...@gmail.com> wrote:
> I'm using getClass().getClassLoader().getResource("plugins") to load a resource.

That is not a resource. That is (perhaps) a URL prefix used for a
variety of resources. And there is no way to enumerate children of a
URL.

Load a particular resource, e.g.

ThisClass.class.getResource("plugins/something.jar")

(preferring the package-relative path scheme) and if it is impractical
to hard-code the list of JARs, save it as a text file during the Maven
build, which text file you can then load as a resource.

Daniel Anechitoaie

unread,
Jul 12, 2018, 2:17:36 PM7/12/18
to Jenkins Developers
That did the trick. Now it's working.

Thank you for your help.
Reply all
Reply to author
Forward
0 new messages