Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [tycho-user] Conventions/procedures for using properties file resources in Tycho-built applications?

Hi David,

the structure to have a src/ folder instead of (src/main/java and src/main/resources, ...) is Eclipse specifc. 
You can put your properties files within that src folder and they should end up in the jar.
If you want, you can put your properties files (or whatever) in a folder next to your "src" directory, but then you have to make sure that the folder/files get added to your build.properties. 
E.g. if you have images and other text files you could set up your project like that:

src/ (with all the java source files)
images/ (with all the images)
resources/ (with all the text resources)

Then you have to add the extra folders to the build.properties so that they end up in the jar:

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
               images/,\
               resources/,\
               .

If you want that your text files within the resources directorie get filtered by the maven-resources plugin, you have to tell maven where to find the files you want to filter by adding something like that to your pom:
 
	<build>
		<resources>
			 <resource>
				<directory>resources</directory>
				<filtering>true</filtering>
				<includes>
					<include>**/*.txt</include>
				</includes>
			</resource>
		</resources>
	</build>

With that setting, all the txt files within the resources directory gets filtered during a mvn resources:resources run and will end up filtered in the final jar.  Within your plugin code they can be access like in any other java project e.g. getClass().getResourceAsStream("/resources/mytext.txt");

If you want to use the OSGi NLS support you might want to take a look at this tutorial:

http://www.vogella.com/tutorials/EclipseInternationalization/article.html

hth
martin

________________________________________
Von: tycho-user-bounces@xxxxxxxxxxx <tycho-user-bounces@xxxxxxxxxxx> im Auftrag von David M. Karr <davidmichaelkarr@xxxxxxxxx>
Gesendet: Freitag, 08. April 2016 17:43
An: Tycho user list
Betreff: [tycho-user] Conventions/procedures for using properties file resources in Tycho-built applications?

I'm familiar with how "typical" Maven applications process properties
files using the maven-resources-plugin, and I've used Maven for many years.

In the Eclipse codebase I inherited, which uses Tycho, I'm going to have
to define some properties that are used at runtime, the values of which
will be stored in the POM for the plugin (of several in a multiproject
build) that needs to access these properties.

As this is my first experience with Tycho and an Eclipse application
build, and as I've found some aspects of the Tycho build process
somewhat surprising, I'm wondering whether there are particular
conventions I should follow for managing properties like this in this
ecosystem.

For instance, I assume I would just store this properties file in
"src/main/resources", use the maven-resources-plugin to filter property
values, and load the file from the classpath.

I noticed that the original authors of this codebase didn't set up a
"typical" Maven Java source code folder structure, they just created a
source folder named "src", and both Java source files and properties
files went into this tree.  That seems lazy to me, but perhaps some
convention or aspect of Tycho and Eclipse makes that a reasonable thing
to do?

In the case of this application, these properties files are all used as
ResourceBundles, and from inspecting the code, it does appear there are
conventions for managing these (extending "NLS", for instance).

For the case I'm looking at, the properties I want to manage don't
represent localizable messages, so they don't need to be managed as
ResourceBundles, although I can see it's tempting to use the existing
practice for loading these, which would mean putting them in a resource
bundle.

Ironically, the number of properties I'm talking about is very small,
perhaps 2-3.
_______________________________________________
tycho-user mailing list
tycho-user@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/tycho-user


Back to the top