Question

I am trying to introduce property files in my bundle (OSGI based with Spring Dynamic Modules). I want to keep properties like database URL, username, password etc. in that property file and want maven to read from that file.

I tried to introduce filtering in my pom:

<properties>
    <database.username>${development_user}</database.username>
</properties>
<build>
    <filters> 
         <filter>src/main/resources/Application_${env}.properties</filter> 
    </filters> 
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <defaultGoal>install</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>bundle</id>
                    <phase>package</phase>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.7</version>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>bundle</id>
                    <phase>package</phase>
                    <goals>
                        <goal>bundle</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <excludes>*/pom.</excludes>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

I have below property in my Application_local.properties file:

development_user=dev_user

But when I build by bundle with command "mvn clean install -Denv=local" system inserts '${development_user}' as value in my database.xml

can someone please help me out in resolving this issue?

Was it helpful?

Solution

Try this-one

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0-alpha-2</version>
            <executions>
                <execution>
                    <id>read</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>src/main/resources/Application_${env}.properties</file>
                        </files>
                    </configuration>
                </execution>                   
            </executions>
        </plugin>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top