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?

On 04/09/2016 09:21 AM, SCHREIBER.Martin wrote:
Hi David,
I am able to get the file into the jar at the right place ("resources" folder) with the filtered content if I use that configuration (without any other configuration):

	<build>
		<resources>
			<resource>
				<directory>resources</directory>
				<targetPath>resources</targetPath>
				<filtering>true</filtering>
				<includes>
					<include>**/*.properties</include>
				</includes>
			</resource>
		</resources>

	</build>

Ok, the "targetPath" property was the key.

Curiously, the documentation for that property says this:
------------------------
Describe the resource target path. For example, if you want that
 resource to appear in a specific package
 (org.apache.maven.messages), you must specify this element
 with this value: org/apache/maven/messages. This is not required
 if you simply put the resources in that directory structure at the
 source, however.
----------------------

The last sentence seems to conflict with our experience.



-martin




-----Ursprüngliche Nachricht-----
Von: tycho-user-bounces@xxxxxxxxxxx [mailto:tycho-user-bounces@xxxxxxxxxxx] Im Auftrag von David M. Karr
Gesendet: Samstag, 09. April 2016 05:55
An: Tycho user list
Betreff: Re: [tycho-user] Conventions/procedures for using properties file resources in Tycho-built applications?

On 04/08/2016 01:12 PM, SCHREIBER.Martin wrote:
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");
The problem with this is that it does put the filtered properties file in the jar, but in the root of the jar, along with the ORIGINAL unfiltered properties file, in the "resources" folder.

I'd really like to get only one copy of the file, the filtered version, in the "resources" folder of the resulting jar.

I found the following bug report and discussion:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=362252 .

Using that advice, I tried the following:
-------------------------
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
              <executions>
                  <execution>
                      <id>filter-properties</id>
                      <phase>prepare-package</phase>
                      <configuration>
<outputDirectory>${project.build.directory}/resources</outputDirectory>
                          <overwrite>true</overwrite>
                          <resources>
                              <resource>
<directory>resources</directory>
<filtering>true</filtering>
                                  <includes> <include>**/*.properties</include>
                                  </includes>
                              </resource>
                          </resources>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
          <plugin>
              <groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
              <version>0.24.0</version>
              <configuration>
                <additionalFileSets>
                  <fileSet>
<directory>${project.build.directory}/resources</directory>
                    <includes>
<include>projectpom.properties</include>
                    </includes>
                  </fileSet>
                </additionalFileSets>
              </configuration>
            </plugin>
      </plugins>
-----------------------

This results in only one copy of the file in the jar, in the "resources"
folder, but it's the unfiltered version.

I imagine the key to this is the two directory values, but I can't figure out what permutation gets me what I want.
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.h
tml

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
_______________________________________________
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
_______________________________________________
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
_______________________________________________
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