bring pom's profile value on jsp - spring

I have dev,local, prod profiles on pom.xml
<profile>
<id>local</id>
<properties>
<env>local</env>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
is it possible to bring this profile value on jsp?
I want to split some area of jsp with different compile option
<c:choose>
<c:when test="${isFlag =='loc'}">
<c:when test="${isFlag =='dev'}">
</>

Related

Maven profiles change groupId

We have three profiles and each one needs to set name and groupId for our clients, but my solution shows warnings in Jenkins compilation and haven't transitive dependencys. A part of my pom:
<artifactId>persistenceLib-${proyecto.nombre}</artifactId>
<version>1.0.0</version>
<groupId>${proyecto.groupId}</groupId>
<dependencies>...</dependencies>
<profiles>
<profile>
<id>client1</id>
<activation><activeByDefault>true</activeByDefault></activation>
<properties>
<proyecto.nombre>Client1Lib</proyecto.nombre>
<proyecto.groupId>com.Client1.product</proyecto.groupId>
</properties>
</profile>
<profile>
<id>client2</id>
<activation><activeByDefault>false</activeByDefault></activation>
<properties>
<proyecto.nombre>Client2Lib</proyecto.nombre>
<proyecto.groupId>com.Client2.product</proyecto.groupId>
</properties>
</profile>
<profile>
<id>client3</id>
<activation><activeByDefault>false</activeByDefault></activation>
<properties>
<proyecto.nombre>Client3Lib</proyecto.nombre>
<proyecto.groupId>com.Client3.product</proyecto.groupId>
</properties>
</profile>
</profiles>
¿What is the correct way for a dynamic IDs?

How to use profile variables to define final properties values?

In Spring Boot, I know I can define profiles on application.yml. However, it's not clear to me how to achieve the same result as in this pom.xml snippet:
...
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<pucomex.config.redis.host>devhost</pucomex.config.redis.host>
<pucomex.config.redis.port>5678</pucomex.config.redis.port>
</properties>
</profile>
<profile>
<id>tst</id>
<properties>
<pucomex.config.redis.host>tsthost</pucomex.config.redis.host>
<pucomex.config.redis.port>1234</pucomex.config.redis.port>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>2.5.0.Final</version>
<configuration>
<properties>
<!-- properties based on profile variables -->
<pucomex.config.redis.host>${pucomex.config.redis.host}</pucomex.config.redis.host>
<pucomex.config.redis.port>${pucomex.config.redis.port}</pucomex.config.redis.port>
<!-- global properties -->
<elastic.port>9200</elastic.port>
<elastic.rhlc.connect.timeout.ms>5000</elastic.rhlc.connect.timeout.ms>
<elastic.rhlc.socket.timeout.ms>60000</elastic.rhlc.socket.timeout.ms>
</properties>
</configuration>
</plugin>
</plugins>
</build>
...
In other words: I want to have some properties values varying according to each profile and then use them to define the value of another property.

Set a property inside a maven profile conditionally, depending on another profile

Is there a way so that, inside a maven profile, I could set a property to one value or another, depending on whether another profile is also active ?
Example: for the sample below,
<profiles>
<profile>
<id>dev</id>
<properties>
<myProp>value-dev</myProp>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<myProp>value-prod</myProp>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<myProp>value-test</myProp>
</properties>
</profile>
</profiles>
if ONLY DEV is active, then I need myProp = value-dev
if DEV and TEST are active, then I need myProp = value-test
How can I achieve this ?
Thanks.

bring maven profiles information on jsp

I have maven properties on pom.xml as follow
pom.xml
<profile>
<id>local</id>
<properties>
<env>local</env>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
if I want what env value from jsp
what should I do?
I want to use this value like
<c:when test=env=='local'>
</c:when>
<c:when test=env=='dev'>
</c:when>
<c:when test=env=='env'>
</c:when>
You need to use the maven resource filtering which works like this:
Create a build.properties in src/main/resources like:
env=${env}
Then add the resource filter to your pom
<properties>
<java.version>1.8</java.version>
<env>prod</env>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
After a build your build,properties will look like :
greg#greg-XPS-13-9360:~/work/jsp-example$ cat target/classes/build.properties
env=prod
You can inject them into the JSP in the normal way, for my example I used Spring boot.
Note if you use Spring Boot the build.properties should be of the format
greg#greg-XPS-13-9360:~/work/jsp-example$ cat src/main/resources/build.properties
env=#env#

Using profiles in Netbeans and Maven multimodule project to build for Windows and Linux

In a NetBeans "workspace" for Java there are several projects (all dirs are on same level):
Main
MainExecutable (contains the main(String[] args) method for debugging)
JNILibrary (only available for Linux)
10 further projects
And I am trying to make it debuggable on Windows by providing "stubs" (just some empty methods) source code for Windows through the profile in JNILibrary\pom.xml:
<groupId>com.example</groupId>
<artifactId>jnilibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.example.test</groupId>
<artifactId>Main</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../Main/pom.xml</relativePath>
</parent>
<build>
<sourceDirectory>${src.dir}</sourceDirectory>
</build>
<profiles>
<profile>
<id>windows</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<src.dir>src/windows/java</src.dir>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<src.dir>src/linux/java</src.dir>
</properties>
</profile>
</profiles>
After that I am able to select Set Configuration -> linux or Set Configuration -> Windows, when I right-click on the JNILibrary project in NetBeans.
Unfortunately, when I try to debug the MainExecutable project - it still (builds and) starts the Linux version - and fails to start on my Windows PC.
Could someone please point into right direction on how to solve my problem?
Here is an excerpt from Main\pom.xml:
<groupId>com.example.test</groupId>
<artifactId>Main</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Main</name>
<modules>
<module>../MainExecutable</module>
<module>../jnilibrary</module>
<module>../10/further/modules</module>
</modules>
And here an excerpt from MainExecutable\pom.xml:
<parent>
<groupId>com.example.test</groupId>
<artifactId>Main</artifactId>
<relativePath>../Main</relativePath>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>MainExecutable</artifactId>
<packaging>jar</packaging>
As you wrote, move the 2 profiles to Main/pom.xml and add to both of them new property jnilibrary.src.dir
<profiles>
<profile>
<id>windows</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<jnilibrary.src.dir>src/windows/java</src.dir>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<jnilibrary.src.dir>src/linux/java</src.dir>
</properties>
</profile>
</profiles>
and use that property in JNILibrary\pom.xml
<build>
<sourceDirectory>${jnilibrary.src.dir}</sourceDirectory>
</build>
You can use the OS Name to activate the profile:
<build>
<sourceDirectory>${src.dir}</sourceDirectory>
</build>
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<name>Windows</name>
</os>
</activation>
<properties>
<src.dir>src/windows/java</src.dir>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<name>Linux</name>
</os>
</activation>
<properties>
<src.dir>src/linux/java</src.dir>
</properties>
</profile>
</profiles>

Resources