You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Costin Caraivan <cc...@axway.com> on 2009/02/13 18:30:06 UTC

src/main/resources and hardcoded paths

Hello,

This will be a newbie question, regarding resource relocation at build time.
It goes like this: I code something, that maybe loads some .properties and
some images. I need the paths to those files, so I hardcode them. Maybe I
even use another .properties file to load these paths at runtime - but I
still need to hardcode the path to this file (or give it as an command line
option, let's say).

Anyway, Maven wants a certain structure, it wants the resources in
src/main/resources (I know it can be configured). But when it builds the
project jar, the resources are moved from that folder.

So:
compile time (in an IDE for example, like Eclipse):
src/main/java/classes
src/main/resources/resources

jar time:
classes
resources

How do you cope with this relocation? If I move everything in
src/main/resources, I'll break the code when compiling with something like
Eclipse (while debugging for example). If I don't, I break Maven (the build
is more complex, I can't really change the resource folder using <resources>
for various reasons).

How do you handle your resources when building with Maven? You just put the
resources in src/main/resources... and what happens when you run your jar?

Thank you for your answers,
Costin.
-- 
View this message in context: http://www.nabble.com/src-main-resources-and-hardcoded-paths-tp22001032p22001032.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: src/main/resources and hardcoded paths

Posted by Stephen Connolly <st...@gmail.com>.
load the resources through the classloader

Sent from my [rhymes with myPod] ;-)

On 13 Feb 2009, at 17:30, Costin Caraivan <cc...@axway.com> wrote:

>
> Hello,
>
> This will be a newbie question, regarding resource relocation at  
> build time.
> It goes like this: I code something, that maybe loads  
> some .properties and
> some images. I need the paths to those files, so I hardcode them.  
> Maybe I
> even use another .properties file to load these paths at runtime -  
> but I
> still need to hardcode the path to this file (or give it as an  
> command line
> option, let's say).
>
> Anyway, Maven wants a certain structure, it wants the resources in
> src/main/resources (I know it can be configured). But when it builds  
> the
> project jar, the resources are moved from that folder.
>
> So:
> compile time (in an IDE for example, like Eclipse):
> src/main/java/classes
> src/main/resources/resources
>
> jar time:
> classes
> resources
>
> How do you cope with this relocation? If I move everything in
> src/main/resources, I'll break the code when compiling with  
> something like
> Eclipse (while debugging for example). If I don't, I break Maven  
> (the build
> is more complex, I can't really change the resource folder using  
> <resources>
> for various reasons).
>
> How do you handle your resources when building with Maven? You just  
> put the
> resources in src/main/resources... and what happens when you run  
> your jar?
>
> Thank you for your answers,
> Costin.
> -- 
> View this message in context: http://www.nabble.com/src-main-resources-and-hardcoded-paths-tp22001032p22001032.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: src/main/resources and hardcoded paths

Posted by Costin Caraivan <cc...@axway.com>.

Mick Knutson-4 wrote:
> 
> You mean like:
> 
> classpath:someresource.properties
> ---
> Thank You…
> 
> Mick Knutson, President
> 
> On Fri, Feb 13, 2009 at 12:30 PM, Costin Caraivan
> <cc...@axway.com>wrote:
>> Hello,
>>
>> This will be a newbie question, regarding resource relocation at build
>> time.
>> It goes like this: I code something, that maybe loads some .properties
>> and
>> some images. I need the paths to those files, so I hardcode them. Maybe I
>> even use another .properties file to load these paths at runtime - but I
>> still need to hardcode the path to this file (or give it as an command
>> line
>> option, let's say).
>>
>> Anyway, Maven wants a certain structure, it wants the resources in
>> src/main/resources (I know it can be configured). But when it builds the
>> project jar, the resources are moved from that folder.
>>
>> So:
>> compile time (in an IDE for example, like Eclipse):
>> src/main/java/classes
>> src/main/resources/resources
>>
>> jar time:
>> classes
>> resources
>>
>> How do you cope with this relocation? If I move everything in
>> src/main/resources, I'll break the code when compiling with something
>> like
>> Eclipse (while debugging for example). If I don't, I break Maven (the
>> build
>> is more complex, I can't really change the resource folder using
>> <resources>
>> for various reasons).
>>
>> How do you handle your resources when building with Maven? You just put
>> the
>> resources in src/main/resources... and what happens when you run your
>> jar?
>>
>> Thank you for your answers,
>> Costin.
> 
So, basically, Maven adds src/main/resources to the classpath and I should
add it too while running Eclipse (or maven-eclipse-plugin does it for me, I
haven't checked - I don't have access to a Maven project right now). The bad
news is that I'm not sure how the resources are loaded, they may be loaded
the wrong way (aka not like this:
http://jaredtech.blogspot.com/2005/05/loading-properties-with-classpath.html)
:(

Thank you,
Costin.
-- 
View this message in context: http://www.nabble.com/src-main-resources-and-hardcoded-paths-tp22001032p22001724.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: src/main/resources and hardcoded paths

Posted by Mick Knutson <mi...@gmail.com>.
You mean like:

classpath:someresource.properties


---
Thank You…

Mick Knutson, President

BASE Logic, Inc.
Enterprise Architecture, Design, Mentoring & Agile Consulting
p. (866) BLiNC-411: (254-6241-1)
f. (415) 685-4233

Website: http://baselogic.com
Linked IN: http://linkedin.com/in/mickknutson
Twitter: http://twitter.com/mickknutson
Vacation Rental: http://tahoe.baselogic.com
---



On Fri, Feb 13, 2009 at 12:30 PM, Costin Caraivan <cc...@axway.com>wrote:

>
> Hello,
>
> This will be a newbie question, regarding resource relocation at build
> time.
> It goes like this: I code something, that maybe loads some .properties and
> some images. I need the paths to those files, so I hardcode them. Maybe I
> even use another .properties file to load these paths at runtime - but I
> still need to hardcode the path to this file (or give it as an command line
> option, let's say).
>
> Anyway, Maven wants a certain structure, it wants the resources in
> src/main/resources (I know it can be configured). But when it builds the
> project jar, the resources are moved from that folder.
>
> So:
> compile time (in an IDE for example, like Eclipse):
> src/main/java/classes
> src/main/resources/resources
>
> jar time:
> classes
> resources
>
> How do you cope with this relocation? If I move everything in
> src/main/resources, I'll break the code when compiling with something like
> Eclipse (while debugging for example). If I don't, I break Maven (the build
> is more complex, I can't really change the resource folder using
> <resources>
> for various reasons).
>
> How do you handle your resources when building with Maven? You just put the
> resources in src/main/resources... and what happens when you run your jar?
>
> Thank you for your answers,
> Costin.
> --
> View this message in context:
> http://www.nabble.com/src-main-resources-and-hardcoded-paths-tp22001032p22001032.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>