0

One of our developers left the team few months ago and, due the short notice we was not able to complete the KT. So, now, I have a project I cannot start (of course is the less used component but, today, of course, has become critical, you know eh...).

So, basically it is a Spring-boot application and this is what we have in pom.xml config:

    <build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>test/main/java</testSourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>assembly</id> <!-- this is used for inheritance merges -->
                    <phase>package</phase> <!-- bind to the packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <finalName>
                            reporting-${owner}-${env}
                        </finalName>
                        <descriptors>
                            <descriptor>reporting-assembly.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>local</id>
        <activation>
            <property>
                <name>env</name>
                <value>local</value>
            </property>
        </activation>
        <properties>
            <config.path>src/main/resources/config/${owner}/local</config.path>
        </properties>
    </profile>
    <profile>
        <id>qa</id>
        <activation>
            <property>
                <name>env</name>
                <value>qa</value>
            </property>
        </activation>
        <properties>
            <config.path>src/main/resources/config/${owner}/qa</config.path>
        </properties>
    </profile>
    <profile>
        <id>staging</id>
        <activation>
            <property>
                <name>env</name>
                <value>staging</value>
            </property>
        </activation>
        <properties>
            <config.path>src/main/resources/config/${owner}/staging</config.path>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <activation>
            <property>
                <name>env</name>
                <value>prod</value>
            </property>
        </activation>
        <properties>
            <config.path>src/main/resources/config/${owner}/prod</config.path>
        </properties>
    </profile>
</profiles>

Every config folder contains the proper env.config file but, when I start the application I'm not able to access to the proper file: basically I don't know where to set on my Run/Debug configuration the owner and env properties.

Even if I set the environment variables ${env} and ${owner} (on debug configurations) I'm still getting null value here:

public static <T> T loadJsonResourceIntoClass(String jsonResourcePath, Class<T> clazz) throws Exception {
    URL jsonFilePathUrl = JsonUtil.class.getClassLoader().getResource(jsonResourcePath);
    return objectMapper.readValue(jsonFilePathUrl != null ? jsonFilePathUrl.openStream() : null, clazz);
}

jsonFilePathUrl is always null

Any clue?

Andrea

Andrea Girardi
  • 4,337
  • 13
  • 69
  • 98

1 Answers1

0

In IntelliJ IDEA I just specify the necessary config/{client}/{environment} folder as “Resources” in the PHR or Reporting module settings, hc/local in this case: Project structure -> Modules -> YourApplicationName -> Sources -> Resources and select the proper file.

In Eclipse the same can be done with the help of Run Configurations:

Create, Manage, and run configuration -> ClassYouWantToRun* -> ClassPath -> User Entries -> Advanced -> Add Folder and choose the configuration folder.

I have also activate the proper maven profile on my IDE.

Andrea Girardi
  • 4,337
  • 13
  • 69
  • 98