Getting outdated version of a Maven project resource in Jenkins

Multi tool use
Multi tool use


Getting outdated version of a Maven project resource in Jenkins



I inherited a project and I stumbled upon this snippet of code which is trying to load a resource in /src/main/resources using the URL given by getSystemResource and getting the stream of it:


/src/main/resources


getSystemResource


try
{
is = new URL(this.getClass().getSystemResource("checker/config.default.xml").toString()).openStream();
FileUtils.copyInputStreamToFile(is, this.configFile);
}
catch (IOException e)
{
log.error("Could not load default config from API resources!", e);
}
finally
{
IOUtils.closeQuietly(is);
}



But after I made some changes to the config file, the snippet of code didn't do what it was supposed to do and still fetched the now outdated version of the config. I also tried with getResource:


getResource


ClassLoader classloader = getClass().getClassLoader();
is = new URL(classloader.getResource("checker/config.default.xml").toString()).openStream();



and finally settled on getResourceAsStream


getResourceAsStream


ClassLoader classloader = this.getClass().getClassLoader();
is = classloader.getResourceAsStream("checker/config.default.xml");



To no avail, although it works when I test the code locally on eclipse and I'm not getting a null when tests are using the tool in Jenkins, the tool still use an outdated configuration from a few releases ago.


null



Also I'm pretty confident that the path I'm using in the method is right. I tried /src/main/resources/checker/config.default.xml or /checker/config.default.xml but it gives me NullPointerException.


/src/main/resources/checker/config.default.xml


/checker/config.default.xml


NullPointerException



EDIT - additional information:
I build locally with Eclipse the jar as Jenkins would do and checked that the correct version of the resource was packed in it too. Also the test workspace is cleaned after each Jenkins run.



I'm at a loss on how to make sure that it always fetch the latest version of the file. Is there an alternative method that I missed? Is it some kind of weird cache issue I'm not aware of?





"logchecker/logchecker-config.default.xml").toString() is exactly the same as "logchecker/logchecker-config.default.xml".Don't write pointless code.
– EJP
Jul 2 at 9:42



"logchecker/logchecker-config.default.xml").toString()


"logchecker/logchecker-config.default.xml"





First you should never read resources file based ...better go via this.getClass().getResourceAsStream("/logchecker/logcheker-config.default.xml") furthermore check if you start with / which means starting in the root location of your src/main/resources.Is the correct file in the resulting jar packaged?
– khmarbaise
Jul 2 at 9:48


this.getClass().getResourceAsStream("/logchecker/logcheker-config.default.xml")


/


src/main/resources


jar





@EJP ("logchecker/logchecker-config.default.xml").toString() is exactly the same as "logchecker/logchecker-config.default.xml" but getResource("logchecker/logchecker-config.default.xml") sends an URL back thus the need of toString()
– Eldros
Jul 2 at 10:10



("logchecker/logchecker-config.default.xml").toString()


"logchecker/logchecker-config.default.xml"


getResource("logchecker/logchecker-config.default.xml")


URL


toString()





Did you run the clean goal on Jenkins? What happens if you manually delete the workspace of the Jenkins job before starting the build?
– werner
Jul 2 at 20:04





@khmarbaise I did a test build in my eclipse and the correct version of the xml was packed in the jar. using a /at the beginning of the path leads to a NPE whereas using a "relative" path (relative to /src/main/resources as it is a maven project) do retrieve me a file. Although it is always the correct one on Eclipse, it is an older version in my Jenkins test.
– Eldros
Jul 3 at 7:55


/


/src/main/resources




1 Answer
1



The checker project was but one of the dependencies of a bigger project.


checker



What I found out is that the older version of the wanted resource came from another dependency.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

DSWDEyuSUjzeST5lMAQn9VXV83 OVUn7QAYQF
RiunC3rs5C0Qx,Ob,S,On4,a4cCPBW giP8cls9sLvdYKwMo r nr8E

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications