I want to open a file in the same dir as the calling script:
It is not found because it´s not in D:\JIRA, which is my dev install dir. The sources are in another dir, D:\Development\JIRA and are set in sentenv.bat.
The production system is linux, so I can´t hardcode any paths.
new File(".").getCanonicalPath() resolves to D:\JIRA
What can I do to load that file?
You should use something like:
getResource will use the classloader to return a URL which is just a pointer to a resource. Then we are just loading the content doing .text
Sometimes you don't know the absolute/relative path or is different on other platforms, so specifying a resource from the classpath to be loaded is useful.
this.class just gets the current class which has access to the classloader associated with that class. Both files are on the classpath so it works.
We could have done MyClass.class.getResource("config.groovy").text which would have given the same.
If you search online theres a ton of information about this if you want further details.
Atlas Camp is our developer event which will take place in Barcelona, Spain from the 6th -7th of September . This is a great opportunity to meet other developers and get n...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG