You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Guy Matz <gu...@gmail.com> on 2016/04/15 18:07:16 UTC

ConfigSlurper not finding Config.groovy in jar

Hi!  I can't seem to find and slurp in a config file that's contained in a
jar.  I think part of the problem may be that the config.groovy file is
being compiled into a class, but can't figure out the right way to go about
slurping it in . . .   from an ancient post I have the following code:

def InputStream is = getClass().getResourceAsStream('/Config.groovy')
def config = new ConfigSlurper().parse(is.getText())

The getClass()...   return null.

My directory structure is:

src/main/resources/Config.groovy

however my jar looks contains Config.class


Anyone know what I'm doing wrong here?

Thanks a lot!

Guy

RE: ConfigSlurper not finding Config.groovy in jar

Posted by Billy Buzzard <bi...@bnsflogistics.com>.
AFAIK under normal circumstances the compiler should only be compiling files that are under the src/main/java folder, but when compiling groovy files it appears all src folders are included like the src/main/resources folder.  I bet you can add a configuration element to the groovy compiler in the pom file that will let you exclude the /src/main/resources folder.

From: Billy Buzzard [mailto:billy.buzzard@bnsflogistics.com]
Sent: Friday, April 15, 2016 1:28 PM
To: users@groovy.apache.org
Subject: RE: ConfigSlurper not finding Config.groovy in jar

The reason “Config.class” is appearing in your jar is because you specified “Config.groovy” in the src/main/resources.  The compiler sees the “.groovy” suffix and compiles the file into a “.class” flie.  Simply changing the filename to something like “Config.properties” should stop the name from changing work.

From: Guy Matz [mailto:guymatz@gmail.com]
Sent: Friday, April 15, 2016 1:02 PM
To: users@groovy.apache.org<ma...@groovy.apache.org>
Subject: Re: ConfigSlurper not finding Config.groovy in jar

As usual, the Groovy solution is far simpler than anticipated.

Thank you!!

On Fri, Apr 15, 2016 at 1:25 PM, John Wagenleitner <jo...@gmail.com>> wrote:
If the build is compiling the file you probably either need to copy it into your jar from another location or you might be able to use the #parse(Class) method of ConfigSlurper.

def config = new ConfigSlurper().parse(Config)

On Fri, Apr 15, 2016 at 9:07 AM, Guy Matz <gu...@gmail.com>> wrote:
Hi!  I can't seem to find and slurp in a config file that's contained in a jar.  I think part of the problem may be that the config.groovy file is being compiled into a class, but can't figure out the right way to go about slurping it in . . .   from an ancient post I have the following code:


def InputStream is = getClass().getResourceAsStream('/Config.groovy')
def config = new ConfigSlurper().parse(is.getText())

The getClass()...   return null.

My directory structure is:

src/main/resources/Config.groovy

however my jar looks contains Config.class



Anyone know what I'm doing wrong here?

Thanks a lot!

Guy





RE: ConfigSlurper not finding Config.groovy in jar

Posted by Billy Buzzard <bi...@bnsflogistics.com>.
The reason “Config.class” is appearing in your jar is because you specified “Config.groovy” in the src/main/resources.  The compiler sees the “.groovy” suffix and compiles the file into a “.class” flie.  Simply changing the filename to something like “Config.properties” should stop the name from changing work.

From: Guy Matz [mailto:guymatz@gmail.com]
Sent: Friday, April 15, 2016 1:02 PM
To: users@groovy.apache.org
Subject: Re: ConfigSlurper not finding Config.groovy in jar

As usual, the Groovy solution is far simpler than anticipated.

Thank you!!

On Fri, Apr 15, 2016 at 1:25 PM, John Wagenleitner <jo...@gmail.com>> wrote:
If the build is compiling the file you probably either need to copy it into your jar from another location or you might be able to use the #parse(Class) method of ConfigSlurper.

def config = new ConfigSlurper().parse(Config)

On Fri, Apr 15, 2016 at 9:07 AM, Guy Matz <gu...@gmail.com>> wrote:
Hi!  I can't seem to find and slurp in a config file that's contained in a jar.  I think part of the problem may be that the config.groovy file is being compiled into a class, but can't figure out the right way to go about slurping it in . . .   from an ancient post I have the following code:


def InputStream is = getClass().getResourceAsStream('/Config.groovy')
def config = new ConfigSlurper().parse(is.getText())

The getClass()...   return null.

My directory structure is:

src/main/resources/Config.groovy

however my jar looks contains Config.class



Anyone know what I'm doing wrong here?

Thanks a lot!

Guy





Re: ConfigSlurper not finding Config.groovy in jar

Posted by Guy Matz <gu...@gmail.com>.
As usual, the Groovy solution is far simpler than anticipated.

Thank you!!

On Fri, Apr 15, 2016 at 1:25 PM, John Wagenleitner <
john.wagenleitner@gmail.com> wrote:

> If the build is compiling the file you probably either need to copy it
> into your jar from another location or you might be able to use the
> #parse(Class) method of ConfigSlurper.
>
> def config = new ConfigSlurper().parse(Config)
>
> On Fri, Apr 15, 2016 at 9:07 AM, Guy Matz <gu...@gmail.com> wrote:
>
>> Hi!  I can't seem to find and slurp in a config file that's contained in
>> a jar.  I think part of the problem may be that the config.groovy file is
>> being compiled into a class, but can't figure out the right way to go about
>> slurping it in . . .   from an ancient post I have the following code:
>>
>> def InputStream is = getClass().getResourceAsStream('/Config.groovy')
>> def config = new ConfigSlurper().parse(is.getText())
>>
>> The getClass()...   return null.
>>
>> My directory structure is:
>>
>> src/main/resources/Config.groovy
>>
>> however my jar looks contains Config.class
>>
>>
>> Anyone know what I'm doing wrong here?
>>
>> Thanks a lot!
>>
>> Guy
>>
>>
>>
>

Re: ConfigSlurper not finding Config.groovy in jar

Posted by John Wagenleitner <jo...@gmail.com>.
If the build is compiling the file you probably either need to copy it into
your jar from another location or you might be able to use the
#parse(Class) method of ConfigSlurper.

def config = new ConfigSlurper().parse(Config)

On Fri, Apr 15, 2016 at 9:07 AM, Guy Matz <gu...@gmail.com> wrote:

> Hi!  I can't seem to find and slurp in a config file that's contained in a
> jar.  I think part of the problem may be that the config.groovy file is
> being compiled into a class, but can't figure out the right way to go about
> slurping it in . . .   from an ancient post I have the following code:
>
> def InputStream is = getClass().getResourceAsStream('/Config.groovy')
> def config = new ConfigSlurper().parse(is.getText())
>
> The getClass()...   return null.
>
> My directory structure is:
>
> src/main/resources/Config.groovy
>
> however my jar looks contains Config.class
>
>
> Anyone know what I'm doing wrong here?
>
> Thanks a lot!
>
> Guy
>
>
>