Accessing Gerrit Resources from Plugin

28 views
Skip to first unread message

Rafael Lima

unread,
Nov 25, 2021, 12:06:52 PM11/25/21
to Repo and Gerrit Discussion
Hi everyone,

I'm trying to use Spring JAVA library inside a Gerrit Plugin.

When I try to start the library by reading a XML file from resources with the below code:

ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");

I got this error message:

class path resource [applicationContext.xml] cannot be opened because it does not exist

The same code works on a stand-alone Spring application.

Already look through the Gerrit documentation / Google looking for any specific points regarding accessing files stored /resources folder in JAR, but found nothing.

Also tried variations of the file name (with classpath prefix and etc) and the only way it worked was by reading a file from system (/data/applicationContext.xml).

Does anyone knows if it is possible to access files on /resources folder from inside a Gerrit Plugin?

PS: Have similar problem when trying to read logback XML configuration files.

Thanks in advance,

Rafael

Matthias Sohn

unread,
Nov 25, 2021, 12:12:27 PM11/25/21
to Rafael Lima, Repo and Gerrit Discussion
Gerrit plugins are loaded each in a separate classloader [1], maybe that's in your way ?

 
Thanks in advance,

Rafael

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/5fbe81a8-e83b-4040-8efd-9161e44059a3n%40googlegroups.com.

Rafael Lima

unread,
Nov 25, 2021, 12:38:03 PM11/25/21
to Repo and Gerrit Discussion
Hi Matthias, thanks for the quick answering.

Yes, it probably has something to do with the way Gerrit loads and handle plugin files.
I'm currently using the shade-plugin to create a package with all the dependencies.
Dependencies looks fine. I can see the Spring library being called.

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

Also, I've read the documentation section [1] that explains what happens with documents placed on /resources/Documentation and /resources/static.
But nothing related about how to access /resource/* files.


Reply all
Reply to author
Forward
0 new messages