rhinds
rhinds

Reputation: 10043

Error loading Groovy config file from JAR

I have an application that is running on compiled Groovy code in a jar.

The groovy code is all being loaded/executed correctly, however, I have a step that attempts to load a groovy-config file from the root of the JAR, but it is failing.

The code below is from a groovy class that is being run from the JAR, and here it attempts to load the groovy config file config.props from the root of the jar:

URL url = this.getClass().getClassLoader().getResource("config.props")
logger.info( url.toString() )
if(!url)throw new IllegalArgumentException("'$resource' not found ")
GroovyScriptEngine gse = new GroovyScriptEngine( url )
...
gse.run(url.file, binding)

When I run the above I get the following error:

Message: Cannot open URL: jar:file:/usr/local/libs/test-all.jar!/config.props

Does anyone have any idea how to load a file from a root of a jar? I have temporarily set the permissions to 777 and have checked that the file exists/spelling correct.

Upvotes: 1

Views: 426

Answers (1)

rhinds
rhinds

Reputation: 10043

Ok - I think I have resolved this.

It looks like the error was in

gse.run(url.file, binding)

the url.file passed the full absolute path including file: protocol to the gse - I changed this to just "config.props" and it seemed to have got past this (there is another error now, but seems to be further on).

Upvotes: 1

Related Questions