Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My .properties file isn't being picked up and my maven profile properties aren't injected

EDIT: if you’re downvoting me then at least comment why please.

I am trying to inject specific details into my datasource.properties file by using maven profiles in my pom.xml

For some reason, it applies the details to other places where its needed such as the hibernate.cfg.xml but it doesn’t apply it to my datasource.properties?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i have added the configuration for where the resources are but not sure what i am missing?

here is the relevant info from my pom.xml

.......
<profiles>
        <profile>
            <id>development</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <property>
                    <name>environment</name>
                    <value>dev</value>
                </property>
            </activation>
            <properties>
                 <db.username>some username</db.username>
                 <db.password>some password</db.password>
                 <db.url>some db url</db.url>
            </properties>
        </profile>
    </profiles>
    
    <properties>
        <db.username>some username</db.username>
        <db.password>some password</db.password>
        <db.url>some db url</db.url>
    </properties>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.1</version>
                <configuration>
                    <warName>APP</warName>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp/META-INF</directory>
                            <filtering>true</filtering>
                            <targetPath>META-INF</targetPath>
                        </resource>                     
                        <resource>
                            <directory>src/main/resources</directory>
                            <filtering>true</filtering>
                            <includes>
                                <include>**/hibernate.cfg.xml</include>
                                <include>**/datasource.properties</include>
                            </includes>
                        </resource>
                        <resource>
                            <directory>src/main/webapp</directory>
                            <filtering>true</filtering>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
    </build>
.......

here is what the format is like in my datasource.properties file

datasource.driverClassName=some driver
datasource.url=${db.url}
datasource.username=${db.username}
datasource.password=${db.password}
datasource.initialPoolSize=10
datasource.minPoolSize=10
datasource.maxPoolSize=20
datasource.maxStatements=50

>Solution :

if you want to replace the placeholder in build time by maven, you have to use resource filtering:

Add this to your <build> section in your pom.xml

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

which your code you do not replace the values and access environment variables at runtime

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading