Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How to use a properties file, internal to the Eclipse project and the jar.
How to use a properties file, internal to the Eclipse project and the jar. [message #814582] Tue, 06 March 2012 16:17 Go to next message
DonCamp  is currently offline DonCamp Friend
Messages: 6
Registered: January 2011
Junior Member
Hi,

I can't figure out how to use a Properties file which is inside the
Eclipse project, and which I want to include in the jar.

The properties file - ErrorCodes.properties - is in the src folder
\Project\src. The main method is in a source file in the
src/java/com.mycompany.err.customcodes folder.



I've tried the following 3 statements, but in all cases ErrorCodeStream
is populated with null.


InputStream ErrorCodeStream =
getClass().getClassLoader().getResourceAsStream("/src/ErrorCodes.properties"
);


InputStream ErrorCodeStream =
getClass().getClassLoader().getResourceAsStream("src/ErrorCodes.properties");



InputStream ErrorCodeStream =
getClass().getClassLoader().getResourceAsStream("ErrorCodes.properties");
Re: How to use a properties file, internal to the Eclipse project and the jar. [message #814600 is a reply to message #814582] Tue, 06 March 2012 16:47 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 3/6/2012 9:17 AM, DonCamp wrote:
>
>
> Hi,
>
> I can't figure out how to use a Properties file which is inside the
> Eclipse project, and which I want to include in the jar.
>
> The properties file - ErrorCodes.properties - is in the src folder
> \Project\src. The main method is in a source file in the
> src/java/com.mycompany.err.customcodes folder.
>
>
>[snip]

Here's a simple article to get you started:

http://www.javahotchocolate.com/topics/resbundle.html
Re: How to use a properties file, internal to the Eclipse project and the jar. [message #814621 is a reply to message #814600] Tue, 06 March 2012 17:17 Go to previous messageGo to next message
DonCamp  is currently offline DonCamp Friend
Messages: 6
Registered: January 2011
Junior Member
Looks detailed enough, thanks Russell.


On 3/6/2012 11:47 AM, Russell Bateman wrote:
> On 3/6/2012 9:17 AM, DonCamp wrote:
>>
>>
>> Hi,
>>
>> I can't figure out how to use a Properties file which is inside the
>> Eclipse project, and which I want to include in the jar.
>>
>> The properties file - ErrorCodes.properties - is in the src folder
>> \Project\src. The main method is in a source file in the
>> src/java/com.mycompany.err.customcodes folder.
>>
>>
>> [snip]
>
> Here's a simple article to get you started:
>
> http://www.javahotchocolate.com/topics/resbundle.html
>
Re: How to use a properties file, internal to the Eclipse project and the jar. [message #814648 is a reply to message #814621] Tue, 06 March 2012 18:06 Go to previous messageGo to next message
DonCamp  is currently offline DonCamp Friend
Messages: 6
Registered: January 2011
Junior Member
Equivalent problem, using ResourceBundle:


Any of the following errors occur:


Can't find bundle for base name src.java.resources.ErrorCodes

Can't find bundle for base name java.resources.ErrorCodes

Can't find bundle for base name /java.resources.ErrorCodes

Can't find bundle for base name /src/java/resources/ErrorCodes


, depending on what is used for the path, e.g.


ResourceBundle rb = ResourceBundle.getBundle("java.resources.ErrorCodes")



Per the instructions at the link

http://www.javahotchocolate.com/topics/resbundle.html,

the ErrorCode.properties file has been placed in src/java/resources
(that's what Eclipse generated, after creating the resources package).





On 3/6/2012 12:17 PM, DonCamp wrote:
> Looks detailed enough, thanks Russell.
>
>
> On 3/6/2012 11:47 AM, Russell Bateman wrote:
>> On 3/6/2012 9:17 AM, DonCamp wrote:
>>>
>>>
>>> Hi,
>>>
>>> I can't figure out how to use a Properties file which is inside the
>>> Eclipse project, and which I want to include in the jar.
>>>
>>> The properties file - ErrorCodes.properties - is in the src folder
>>> \Project\src. The main method is in a source file in the
>>> src/java/com.mycompany.err.customcodes folder.
>>>
>>>
>>> [snip]
>>
>> Here's a simple article to get you started:
>>
>> http://www.javahotchocolate.com/topics/resbundle.html
>>
>
Re: How to use a properties file, internal to the Eclipse project and the jar. [message #814649 is a reply to message #814648] Tue, 06 March 2012 18:11 Go to previous message
DonCamp  is currently offline DonCamp Friend
Messages: 6
Registered: January 2011
Junior Member
Never mind, got it. Had to take the path out completely, using instead:


ResourceBundle rb = ResourceBundle.getBundle("ErrorCodes");






On 3/6/2012 1:06 PM, DonCamp wrote:
> Equivalent problem, using ResourceBundle:
>
>
> Any of the following errors occur:
>
>
> Can't find bundle for base name src.java.resources.ErrorCodes
>
> Can't find bundle for base name java.resources.ErrorCodes
>
> Can't find bundle for base name /java.resources.ErrorCodes
>
> Can't find bundle for base name /src/java/resources/ErrorCodes
>
>
> , depending on what is used for the path, e.g.
>
>
> ResourceBundle rb = ResourceBundle.getBundle("java.resources.ErrorCodes")
>
>
>
> Per the instructions at the link
>
> http://www.javahotchocolate.com/topics/resbundle.html,
>
> the ErrorCode.properties file has been placed in src/java/resources
> (that's what Eclipse generated, after creating the resources package).
>
>
>
>
>
> On 3/6/2012 12:17 PM, DonCamp wrote:
>> Looks detailed enough, thanks Russell.
>>
>>
>> On 3/6/2012 11:47 AM, Russell Bateman wrote:
>>> On 3/6/2012 9:17 AM, DonCamp wrote:
>>>>
>>>>
>>>> Hi,
>>>>
>>>> I can't figure out how to use a Properties file which is inside the
>>>> Eclipse project, and which I want to include in the jar.
>>>>
>>>> The properties file - ErrorCodes.properties - is in the src folder
>>>> \Project\src. The main method is in a source file in the
>>>> src/java/com.mycompany.err.customcodes folder.
>>>>
>>>>
>>>> [snip]
>>>
>>> Here's a simple article to get you started:
>>>
>>> http://www.javahotchocolate.com/topics/resbundle.html
>>>
>>
>
Previous Topic:visual editor for eclipse IDE for Java Developers
Next Topic:Import/link file with header (permanent)
Goto Forum:
  


Current Time: Fri Mar 29 06:39:56 GMT 2024

Powered by FUDForum. Page generated in 0.04876 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top