I'm trying to setup properties in my config.ini
which located in src/main/config
by using pom.xml
as described in this answer, but it doesn't work.
I've placed to src/main/config
file config.ini
where the following line is present: runtime_mode=${runtime.mode}
when I try to access at runtime runtime_mode
key I get string ${runtime.mode}
instead of DEBUG or PRODUCTION as defined in pom.xml
. When I use ${runtime.mode}
in *.html
file it's being replaced by appropriate value as expected.
So, it doesn't work only when resource located at build path.
I suspect that I define resource in a wrong way, but can't realize what's wrong.
This is build part of my pom.xml
:
<project>
<properties>
<runtime.mode>DEBUG</runtime.mode>
</properties>
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<directory>src/main/config</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>bower.json</include>
<include>index.html</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
My app is a war
project created by using the following archetype:
<archetype>
<groupId>com.ibm.tools.archetype</groupId>
<artifactId>webapp-jee7-liberty</artifactId>
<version>1.0</version>
<description>JEE7 web application targeting WebSphere Liberty archetype</description>
</archetype>
UPDATE:
Moved my config.ini
to src\main\resources
and changed my <resource>
tag as following:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>config.ini</include>
</includes>
</resource>
</resources>
But now I can't read any resource located in src/main/resources
from code, for example I put there sql.xml
where all my sql queries.
Trying read by following code:
private static Properties readProperties(String xmlFileName) throws Exception {
Properties properties = new Properties();
InputStream is = SQLProvider.class.getClassLoader().getResourceAsStream(xmlFileName);
properties.loadFromXML(is);
return properties;
}
But it throws an error:
java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203) ~[?:1.8.0_45]
at java.util.Properties.loadFromXML(Properties.java:881) ~[?:1.8.0_45]
at ***.SQLProvider.readProperties(SQLProvider.java:26) ~[classes/:?]