Gluon Client Maven Plugin - Resource filtering isn't working on 'client:package' - gluon

I am working on a javafx 11 mobile project and Gluon client plugin is being used to build APK.
From this single project we need to build multiple apps (APKs) for different customers. I've done that using maven profiles.
Now I am trying to update 'AndroidManifest.xml' dynamically to set different package name for each builds. I've tried maven resource filtering to update that property dynamically. It's not working as expected.
Below is the 'AndroidManifest.xml' (in src/android):
<?xml version='1.0'?>
<manifest xmlns:android='http://schemas.android.com/apk/res/android'
package='${app.package.name}'
android:versionCode='${app.version.code}'
android:versionName='${app.version.name}'>
<supports-screens android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:label="${app.name}" android:icon="#mipmap/ic_launcher">
<activity android:name='com.gluonhq.helloandroid.MainActivity' android:configChanges="orientation|keyboardHidden">
<intent-filter>
<category android:name='android.intent.category.LAUNCHER'/>
<action android:name='android.intent.action.MAIN'/>
</intent-filter>
</activity>
<activity android:name='com.gluonhq.helloandroid.PermissionRequestActivity'/>
</application>
As you can see above, package, versionCode, versionName and appLabel are defined as filter variables.
Below is the manifest in "target\classes" after executing mvn client:build -P android command.
<?xml version='1.0'?>
<manifest xmlns:android='http://schemas.android.com/apk/res/android'
package='com.company.parent.app'
android:versionCode='1'
android:versionName='1.0'>
<supports-screens android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:label="CB Parents" android:icon="#mipmap/ic_launcher">
<activity android:name='com.gluonhq.helloandroid.MainActivity' android:configChanges="orientation|keyboardHidden">
<intent-filter>
<category android:name='android.intent.category.LAUNCHER'/>
<action android:name='android.intent.action.MAIN'/>
</intent-filter>
</activity>
<activity android:name='com.gluonhq.helloandroid.PermissionRequestActivity'/>
</application>
Below is the manifest in "target\client\aarch64-android\gvm\android_project\app\src\main" after executing mvn client:package -P android command.
<?xml version='1.0'?>
<manifest xmlns:android='http://schemas.android.com/apk/res/android'
package='${app.package.name}'
android:versionCode='${app.version.code}'
android:versionName='${app.version.name}'>
<supports-screens android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:label="${app.name}" android:icon="#mipmap/ic_launcher">
<activity android:name='com.gluonhq.helloandroid.MainActivity' android:configChanges="orientation|keyboardHidden">
<intent-filter>
<category android:name='android.intent.category.LAUNCHER'/>
<action android:name='android.intent.action.MAIN'/>
</intent-filter>
</activity>
<activity android:name='com.gluonhq.helloandroid.PermissionRequestActivity'/>
</application>
Because the filters are not applied as expected, the 'mvn client:package -P android' task fails.
Below is how I applied filtering for AndroidManifest in pom.xml.
<!-- To set AndroidManifest properties dynamically -->
<resource>
<directory>src/android</directory>
<!-- Map ${} into resources -->
<filtering>true</filtering>
<includes>
<include>AndroidManifest.xml</include>
</includes>
</resource>
Why is filtering not working only with 'mvn client:package' task while it works with 'mvn client:build' task? or Am I missing anything?
PS. It's also possible to update 'appLabel', 'versionCode' and 'versionName' through client plugin configuration. But I want to keep every dynamic properties in a single properties file. And also there's no option to set 'packageName' through that plugin. That's why I am updating them through resource filtering.
Update #1: Here is my pom.xml. It's not polished yet.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>multi-profile-project3</groupId>
<artifactId>multi-profile-project3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<main.class>com.multiprofile.app.main.Main</main.class>
</properties>
<build>
<!-- Loading all ${} -->
<filters>
<filter>src/${env}/resources/application-${env}.properties</filter>
</filters>
<resources>
<!-- Loading fxml and css (under 'main' directory) -->
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<!-- Loading main resources -->
<resource>
<directory>src/main/resources</directory>
<!-- Map ${} into resources -->
<filtering>true</filtering>
<includes>
<include>*.properties</include>
</includes>
</resource>
<!-- Loading school specific resources based on 'env' -->
<resource>
<directory>src/${env}/resources</directory>
<excludes>
<exclude>*.properties</exclude>
</excludes>
</resource>
<!-- To set AndroidManifest properties dynamically -->
<resource>
<directory>src/android</directory>
<!-- Map ${} into resources -->
<filtering>true</filtering>
<includes>
<include>AndroidManifest.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version>
<configuration>
<mainClass>${main.class}</mainClass>
</configuration>
</plugin>
<!-- Copy images from src/{env}/resources/images/android_res
to src/android/res -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>id.initresources</id>
<phase>validate</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/android/res</outputDirectory>
<resources>
<resource>
<directory>src/${env}/resources/images/android_res</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${main.class}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<!-- To load properties from '.properties' file and use them as a property -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>id.validateprops</id>
<phase>validate</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/${env}/resources/application-${env}.properties</file>
</files>
</configuration>
</execution>
<execution>
<id>id.outputprops</id>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>${project.build.outputDirectory}/properties-from-pom.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.gluonhq</groupId>
<artifactId>client-maven-plugin</artifactId>
<version>0.1.36</version>
<configuration>
<target>${client.target}</target>
<mainClass>${main.class}</mainClass>
<reflectionList>
<list>com.multiprofile.app.login.LoginPresenter</list>
</reflectionList>
<bundlesList>
<list>application</list>
</bundlesList>
<releaseConfiguration>
</releaseConfiguration>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>school1</id>
<properties>
<env>school1</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>school2</id>
<properties>
<env>school2</env>
</properties>
</profile>
<profile>
<id>school3</id>
<properties>
<env>school3</env>
</properties>
</profile>
<!-- Profile for android build -->
<profile>
<id>android</id>
<properties>
<client.target>android</client.target>
</properties>
</profile>
<!-- Profile for ios build -->
<profile>
<id>ios</id>
<properties>
<client.target>ios</client.target>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>com.airhacks</groupId>
<artifactId>afterburner.fx</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</project>
So, there are profiles for android, ios and for each schools. I use following maven commands for building and packaging "mvn client:build -P school1,android", "mvn client:package -P school1,android" respectively.

Related

Can not resolve ${project.parent.version} to download dependency

i am using/tried with following versions:
Intellij 2022.3.3 and the prev. one.
Maven 3.8.5, 3.8.4, 3.8.1
I also tried following envs:
Maven-Tool integrated into IntelliJ
IntelliJ terminal
OS terminal
And i always get this error:
[WARNING] The POM for io.swagger:swagger-annotations:jar:${project.parent.version} is missing, no dependency information available
Could not find artifact io.swagger:swagger-annotations:pom:${project.parent.version} in mirror-maven.
[INFO]
[INFO] --- openapi-generator-maven-plugin:5.1.0:generate (generate) # XXX-parent-application ---
[WARNING] The POM for io.swagger.core.v3:swagger-annotations:jar:${project.parent.version} is missing, no dependency information available
[WARNING] The POM for io.swagger.core.v3:swagger-models:jar:${project.parent.version} is missing, no dependency information available
[WARNING] The POM for io.swagger.parser.v3:swagger-parser-v2-converter:jar:${project.parent.version} is missing, no dependency information available
[WARNING] The POM for io.swagger.parser.v3:swagger-parser-v3:jar:${project.parent.version} is missing, no dependency information available
[WARNING] The POM for org.openapitools:openapi-generator-core:jar:${project.parent.version} is missing, no dependency information available
[INFO] --- swagger-maven-plugin:3.1.8:generate (default) # XXX-projectname ---
[WARNING] The POM for io.swagger:swagger-annotations:jar:${project.parent.version} is missing, no dependency information available
[WARNING] The POM for io.swagger:swagger-core:jar:${project.parent.version} is missing, no dependency information available
[WARNING] The POM for io.swagger:swagger-jaxrs:jar:${project.parent.version} is missing, no dependency information available
URL_TO_MY_CENTRAL_REPO/io/swagger/core/v3/swagger-annotations/$%7Bproject.parent.version%7D/swagger-annotations-$%7Bproject.parent.version%7D.pom
I am the only one in my team who has this issue, we checked a lot of stuff:
delete maven-repo-folder
check maven-configuration in intellij and settings.xml
insert a static version (but it does not overwrite ${project.parent.version}
yes, it does exist on our artifactory-server
fresh pull from github
So, my question is, where can i find this used property, because i cant find it anywhere in the project.
Update:
added pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>PARENT</artifactId>
<groupId>GROUP_ID_APP</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<modules>
<module>application-a</module>
<module>application-b</module>
<module>application-c</module>
<module>application-d</module>
</modules>
<artifactId>PARENT-application</artifactId>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<!--Properties for swagger generating-->
<swaggerJsonDir>${basedir}/target/generated</swaggerJsonDir>
<swaggerJsonVersion>${project.version}</swaggerJsonVersion>
<swaggerLocation>Override in child project</swaggerLocation>
<swaggerTitle>Override in child project</swaggerTitle>
<!--Override in child project with "compile"-->
<swaggerPhase>none</swaggerPhase>
<!--Properties for client generation-->
<client-generation-application-package>Override in child project</client-generation-application-package>
<sonar.exclusions>
**/foldername/**/*_generated/**/*.java
</sonar.exclusions>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- START: added this part below to check if this may solve my problem -->
<!-- <dependency>-->
<!-- <groupId>io.swagger</groupId>-->
<!-- <artifactId>swagger-core</artifactId>-->
<!-- <version>1.6.5</version>-->
<!-- </dependency>-->
<!-- 2.1.23 -->
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-models -->
<!-- <dependency>-->
<!-- <groupId>io.swagger.core.v3</groupId>-->
<!-- <artifactId>swagger-models</artifactId>-->
<!-- <version>2.1.13</version>-->
<!-- </dependency>-->
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>2.0.30</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.4.0</version>
</dependency>
<!-- END: added this part above to check if this may solve my problem -->
</dependencies>
<build>
<plugins>
<!--Build executable jar from spring application.-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<!--Generate swagger.json-->
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>3.1.8</version>
<configuration>
<apiSources>
<apiSource>
<springmvc>true</springmvc>
<locations>
<location>${swaggerLocation}</location>
</locations>
<info>
<title>${swaggerTitle}</title>
<version>${swaggerJsonVersion}</version>
</info>
<outputFormats>json</outputFormats>
<swaggerDirectory>${swaggerJsonDir}</swaggerDirectory>
</apiSource>
</apiSources>
</configuration>
<executions>
<execution>
<phase>${swaggerPhase}</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>generate-application-b-client</id>
<properties>
<maven.test.skip>true</maven.test.skip>
<input>${project.basedir}/../application-b/target/generated/swagger.json</input>
<targetDirectory>${project.basedir}/target/application-b</targetDirectory>
<modelPackage>GROUP_ID_APP.${client-generation-application-package}.application_b_generated.model</modelPackage>
<apiPackage>GROUP_ID_APP.${client-generation-application-package}.application_b_generated.service.client</apiPackage>
<sourceDirectory>src/main/javapackagefoldername/${client-generation-application-package}</sourceDirectory>
<modelDirectory>${sourceDirectory}/application_b_generated/model</modelDirectory>
<apiDirectory>${sourceDirectory}/application_b_generated/service</apiDirectory>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>
<id>generate</id>
<phase>integration-test</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${input}</inputSpec>
<output>${targetDirectory}</output>
<skipValidateSpec>true</skipValidateSpec>
<generatorName>java</generatorName>
<modelPackage>${modelPackage}</modelPackage>
<apiPackage>${apiPackage}</apiPackage>
<typeMappings>
<typeMapping>OffsetDateTime=LocalDateTime</typeMapping>
</typeMappings>
<importMappings>
<importMapping>java.time.OffsetDateTime=java.time.LocalDateTime</importMapping>
</importMappings>
<configOptions>
<modelPackage>${modelPackage}</modelPackage>
<apiPackage>${apiPackage}</apiPackage>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<library>resttemplate</library>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-models</id>
<phase>integration-test</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${modelDirectory}</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${targetDirectory}/${modelDirectory}</directory>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-services</id>
<phase>integration-test</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${apiDirectory}</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${targetDirectory}/${apiDirectory}</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>clean-old</id>
<phase>compile</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${modelDirectory}</directory>
</fileset>
<fileset>
<directory>${apiDirectory}</directory>
</fileset>
</filesets>
</configuration>
</execution>
<execution>
<id>auto-clean</id>
<phase>integration-test</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${targetDirectory}</directory>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>generate-application-a-client</id>
<properties>
<maven.test.skip>true</maven.test.skip>
<input>${project.basedir}/../application-a/target/generated/swagger.json</input>
<targetDirectory>${project.basedir}/target/application-a</targetDirectory>
<modelPackage>GROUP_ID_APP.${client-generation-application-package}.application_a_generated.model</modelPackage>
<apiPackage>GROUP_ID_APP.${client-generation-application-package}.application_a_generated.service.client</apiPackage>
<sourceDirectory>src/main/javapackagefoldername/${client-generation-application-package}</sourceDirectory>
<modelDirectory>${sourceDirectory}/application_a_generated/model</modelDirectory>
<apiDirectory>${sourceDirectory}/application_a_generated/service</apiDirectory>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>
<id>generate</id>
<phase>integration-test</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${input}</inputSpec>
<output>${targetDirectory}</output>
<skipValidateSpec>true</skipValidateSpec>
<generatorName>java</generatorName>
<modelPackage>${modelPackage}</modelPackage>
<apiPackage>${apiPackage}</apiPackage>
<typeMappings>
<typeMapping>OffsetDateTime=LocalDateTime</typeMapping>
</typeMappings>
<importMappings>
<importMapping>java.time.OffsetDateTime=java.time.LocalDateTime</importMapping>
</importMappings>
<configOptions>
<modelPackage>${modelPackage}</modelPackage>
<apiPackage>${apiPackage}</apiPackage>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<library>resttemplate</library>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-models</id>
<phase>integration-test</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${modelDirectory}</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${targetDirectory}/${modelDirectory}</directory>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-services</id>
<phase>integration-test</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${apiDirectory}</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${targetDirectory}/${apiDirectory}</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>clean-old</id>
<phase>compile</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${modelDirectory}</directory>
</fileset>
<fileset>
<directory>${apiDirectory}</directory>
</fileset>
</filesets>
</configuration>
</execution>
<execution>
<id>auto-clean</id>
<phase>integration-test</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${targetDirectory}</directory>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Maven often doesn't resolve version number for transitive dependencies - "${project.version}"
ill post my solution there.

Deploy as ROOT and SpringLoaded Hippo CMS

Spring Loaded has been working fine for me until I recently switched to deploy as root.
(to completely get rid of the "/site" in the URLs of my website)
I've modified the original config brought up by Jeroen here but it's not working.
(The files under ${project.basedir}/target/tomcat7x/webapps/ROOT is not updated and the website is referring to this outdated source instead of the up-to-date ${project.basedir}/site/target/ROOT)
What am I missing?
My ${project.basedir}/pom.xml:
<profile>
<id>cargo.run</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-tomcat-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/contexts</outputDirectory>
<resources>
<resource>
<directory>conf</directory>
<includes>
<include>*-context.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<configuration>
<properties>
<cargo.jvmargs>-Xmx1920m -Xdebug -Xrunjdwp:transport=dt_socket,address=${cargo.debug.address},server=y,suspend=${cargo.debug.suspend} -noverify -javaagent:/Users/eric/libs/springloaded.jar ${cargo.jvm.args}</cargo.jvmargs>
</properties>
<configfiles>
<configfile>
<file>${project.build.directory}/contexts/site-context.xml</file>
<todir>conf/Catalina/localhost/</todir>
<tofile>site.xml</tofile>
</configfile>
</configfiles>
</configuration>
</configuration>
</plugin>
...
</plugins>
</build>
</profile>
My ${project.basedir}/site/pom.xml
<finalName>ROOT</finalName>
...
<plugin>
<groupId>com.googlecode.mavenfilesync</groupId>
<artifactId>maven-filesync-plugin</artifactId>
<configuration>
<mappings>
<mapping>
<sourceFolder>src/main/resources</sourceFolder>
<destinationFolder>#../target/tomcat${cargo.tomcat.major.version}x/webapps/site/WEB-INF/classes</destinationFolder>
</mapping>
<mapping>
<sourceFolder>src/main/webapp</sourceFolder>
<destinationFolder>#../target/tomcat${cargo.tomcat.major.version}x/webapps/site</destinationFolder>
</mapping>
</mappings>
</configuration>
</plugin>
${project.basedir}/conf/site-context.xml (I've tried having both path as empty string and "/" and neither works)
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/" docBase="${project.basedir}/site/target/ROOT">
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" searchVirtualFirst="true"
virtualClasspath="${project.basedir}/site/target/classes" />
</Context>
Because you renamed the deployed application to ROOT you might need to also change the name of the site-context.xml to ROOT.xml. According to the Tomcat context docs it's required to match the war files name.
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<configuration>
<properties>
<cargo.jvmargs>-Xmx1920m -Xdebug -Xrunjdwp:transport=dt_socket,address=${cargo.debug.address},server=y,suspend=${cargo.debug.suspend} -noverify -javaagent:/Users/eric/libs/springloaded.jar ${cargo.jvm.args}</cargo.jvmargs>
</properties>
<configfiles>
<configfile>
<file>${project.build.directory}/contexts/site-context.xml</file>
<todir>conf/Catalina/localhost/</todir>
<tofile>ROOT.xml</tofile>
</configfile>
</configfiles>
</configuration>
</configuration>
</plugin>

POM How to include properties file inside a jar. The pom also creates a war

I developed a pom that creates a war file and a jar file. How do I insert a properties file into the JAR(not the war)? The file I need to insert into the JAR is located in the directory, properties/its, within the project. You can see in the pom below in the maven-resources-plugin where I have attempted to add the properties file in the package phase with the associated jar goal. Then I tried again in the maven-jar-plugin, using the process-resources phase and jar goal.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxx.xx.Lookup</groupId>
<artifactId>lookup</artifactId>
<packaging>war</packaging>
<version>${env.ENVIRONMENT}</version>
<name>elookup</name>
<url>http://maven.apache.org</url>
<description>Lookup</description>
<dependencies>
<dependency>
<groupId>xxx.xxx.utils</groupId>
<artifactId>Utils</artifactId>
<version>${env.ENVIRONMENT}</version>
</dependency>
</dependencies>
<parent>
<groupId>xxx.xx.parent_project</groupId>
<artifactId>xxxProject</artifactId>
<version>master-version-1.0</version>
<relativePath>../Project/pom.xml</relativePath>
</parent>
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>${env.ENVIRONMENT}</env>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<env>${env.ENVIRONMENT}</env>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<env>${env.ENVIRONMENT}</env>
</properties>
</profile>
</profiles>
<build>
<finalName>${project.name}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>properties/its</directory>
<!-- override the destination directory for this resource -->
<targetPath>properties/its</targetPath>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp/META-INF</directory>
<!-- override the destination directory for this resource -->
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp/WEB-INF</directory>
<!-- override the destination directory for this resource -->
<targetPath>WEB-INF</targetPath>
<filtering>true</filtering>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>images</directory>
<!-- override the destination directory for this resource -->
<targetPath>images</targetPath>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>style</directory>
<!-- override the destination directory for this resource -->
<targetPath>style</targetPath>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>html</directory>
<!-- override the destination directory for this resource -->
<targetPath>.</targetPath>
</resource>
</webResources>
<packagingExcludes>WEB-INF/lib/stax-api-1.0.1.jar</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<configuration>
<!-- specify UTF-8, ISO-8859-1 or any other file encoding -->
<encoding>UTF-8</encoding>
<executions>
<execution>
<id>make-a-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<resources>
<resource>
<directory>properties/its</directory>
<includes>
<include>**/*</include>
</includes>
<!-- <targetPath>.</targetPath> -->
</resource>
</resources>
</execution>
</executions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>make-a-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</execution>
<execution>
<id>jar-resources</id>
<phase>process-resources</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>properties/its</directory>
<targetPath>.</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptor>src/main/assembly/jar.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>../../Project/workspace/src/main/filters/eddb.${env.ENVIRONMENT}.properties</filter>
</filters>
</build>
</project>
How do I insert a properties file into the JAR(not the war)? The file I need to insert into the JAR is located in the directory, properties/its, within the project.
Before package the jar use maven-antrun-plugin to copy your file into the same directory the maven-jar-plugin uses as source directory for jar-ing.

Not getting values from properties files in context.xml file

I am unable to retrieve value from .properties file into my context.xml
pom.xml ( didn't mention dependencies )
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>myproj</artifactId>
<version>0.1.1</version>
<packaging>war</packaging>
<name>myproj</name>
<url>http://maven.apache.org</url>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>dev</env>
<build.number>0</build.number>
<svn.revision.number>0</svn.revision.number>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/environment</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8</version>
<configuration>
<printSummary>false</printSummary>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/*_Roo_*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.7</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<wtpversion>2.0</wtpversion>
<additionalBuildcommands>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
<aspectPath>org.springframework.aspects</aspectPath>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
</buildCommand>
</additionalBuildcommands>
<additionalProjectnatures>
<projectnature>org.eclipse.ajdt.ui.ajnature</projectnature>
<projectnature>com.springsource.sts.roo.core.nature</projectnature>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warName>myproj</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
context.xml (inside src/main/webapp/META-INF)
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- Specify a JDBC datasource -->
<Resource name="jdbc/mydb" auth="Container"
type="javax.sql.DataSource" username="${database.usernameee}" password="${database.password}"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sybase://localhost:9000/common_db"
maxActive="10" maxIdle="4" />
</Context>
I have some .properties files inside under:
src/main/resources
src/main/environment/dev
I am unable to get values inside my context.xml of ${database.usernameee} and ${database.password}
please suggest what went wrong?
Do the following:
1) Remove the <resources> section. It's not needed for the filtering you want to do and src/main/resources is the default - it doesn't need to specified separately.
<build>
<!-- Delete the <resources> section -->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/environment</directory>
<filtering>false</filtering>
</resource>
</resources>
2) Add a <filters> element under <build> specifying the environment specific properties file
<build>
<filters>
<filter>src/main/environment/${env}/some.properties</filter>
</filters>
...
The above assumes your properties files are called some.properties - so change this to the real name of your file.
3) Modify the configuration of the maven-war-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<includes>
<include>**/META-INF/context.xml</include>
</includes>
</resource>
</webResources>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
<warName>myproj</warName>
</configuration>
</plugin>
That will now filter the context.xml using the environment specific properties - depending upon what profile you used.
(note that you may have a typo in 'database.usernameee' - as it has extra ee at the end)
If you want to get your Maven properties from external files (not from properties inside POM's), you should use Maven Filters: see here and here.

Maven property not set when using profile

The filtering via maven package -Pexplode is not working. "${ds.xml}" is not being replaced with "openmind-ds.xml". The value "openmind-ds.xml" and key "ds.xml" are in the filter.properties. Also ${as.deploy}.
Error Message
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (package) on project openmind-ear: An Ant BuildException has occured: Warning: Could not find file /home/localhost/workspaceOM/openmind/openmind-ear/target/${ds.xml} to copy. -> [Help 1]
Mode Debug
[INFO] Executing tasks
[DEBUG] getProperty(ns=null, name=ant.reuse.loader, user=false)
[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
[DEBUG] getProperty(ns=null, name=as.deploy, user=false)
Property "as.deploy" has not been set
Setting project property: deploy-path -> ${as.deploy}/openmind-ear.ear
[DEBUG] getProperty(ns=null, name=deploy-path, user=false)
[echo] Exploding to ${as.deploy}/openmind-ear.ear
[DEBUG] getProperty(ns=null, name=deploy-path, user=false)
[delete] Directory /home/localhost/workspaceOM/openmind/openmind-ear/${as.deploy}/openmind-ear.ear cannot be removed using the file attribute. Use dir instead.
[DEBUG] getProperty(ns=null, name=deploy-path, user=false)
[mkdir] Skipping /home/localhost/workspaceOM/openmind/openmind-ear/${as.deploy}/openmind-ear.ear because it already exists.
[DEBUG] getProperty(ns=null, name=deploy-path, user=false)
[sync] PASS#1: Copying files to /home/argonist/om-umgebung/workspaceOM/openmind/openmind-ear/${as.deploy}/openmind-ear.ear
pom.xml in ear-project
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.openmind</groupId>
<artifactId>openmind</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>openmind-ear</artifactId>
<packaging>ear</packaging>
<name>${project.artifactId} : ${project.version} EAR</name>
<profiles>
<profile>
<id>env-dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>env-prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
<profile>
<id>explode</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<configuration>
<tasks>
<property name="deploy-path" value="${as.deploy}/${app.context}-ear.ear" />
<echo>Exploding to ${deploy-path}</echo>
<delete file="${deploy-path}" quiet="true" />
<mkdir dir="${deploy-path}" />
<sync todir="${deploy-path}" verbose="true">
<fileset
dir="${project.build.directory}/${project.build.finalName}" />
</sync>
<copy todir="${as.deploy}" file="${project.build.directory}/${ds.xml}"
verbose="true" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>unexplode</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>clean</id>
<phase>clean</phase>
<configuration>
<tasks>
<property name="deploy-path" value="${as.deploy}/${app.context}-ear.ear" />
<echo>Unexploding: ${deploy-path}</echo>
<delete file="${deploy-path}" quiet="true" />
<delete dir="${deploy-path}" quiet="true" />
<delete file="${as.deploy}/${ds.xml}" quiet="true" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
.....
</dependencies>
<build>
<finalName>${app.context}-ear</finalName>
<filters>
<filter>../src/main/filters/filter-${env}.properties</filter>
</filters>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<defaultJavaBundleDir>lib/</defaultJavaBundleDir>
<version>6</version>
<archive>
<manifestEntries>
<Build-Date>${timestamp}</Build-Date>
<Build-Revision>${buildNumber}</Build-Revision>
<Mode>${env}</Mode>
</manifestEntries>
</archive>
<modules>
<jarModule>
<groupId>org.jboss.el</groupId>
<artifactId>jboss-el</artifactId>
<includeInApplicationXml>false</includeInApplicationXml>
<bundleDir>lib</bundleDir>
</jarModule>
<jarModule>
<groupId>${project.groupId}</groupId>
<artifactId>${app.context}-datamodel</artifactId>
<includeInApplicationXml>false</includeInApplicationXml>
<bundleDir>lib</bundleDir>
</jarModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>${app.context}-war</artifactId>
<contextRoot>/${app.web.context}</contextRoot>
<unpack>${app.unpack.modules}</unpack>
<bundleFileName>${app.context}-war.war</bundleFileName>
</webModule>
<ejbModule>
<groupId>${project.groupId}</groupId>
<artifactId>${app.context}-bootstrap</artifactId>
<excluded>${exclude.bootstrap}</excluded>
<bundleFileName>${app.context}-bootstrap.jar</bundleFileName>
<unpack>${app.unpack.modules}</unpack>
</ejbModule>
<ejbModule>
<groupId>${project.groupId}</groupId>
<artifactId>${app.context}-ejb</artifactId>
<bundleFileName>${app.context}-ejb.jar</bundleFileName>
<unpack>${app.unpack.modules}</unpack>
</ejbModule>
<ejbModule>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
</ejbModule>
</modules>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<executions>
<execution>
<configuration>
<files>
<file>${basedir}/../src/main/filters/filter-${env}.properties</file>
</files>
</configuration>
</execution>
<execution>
<!-- Properties needed by unexplode profile -->
<id>pre-clean</id>
<phase>pre-clean</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/../src/main/filters/filter-${env}.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- <outputDirectory>${env.JBOSS_HOME}/server/default/deploy</outputDirectory> -->
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>${ds.xml}</include>
</includes>
</resource>
</resources>
</configuration>
<executions>
<execution>
<id>copy-app-ds-xml</id>
<goals>
<goal>copy-resources</goal>
</goals>
</execution>
</executions>
<!-- <execution> <id>copy-mysql-driver</id> <phase>install</phase> <goals>
<goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${env.JBOSS_HOME}/server/default/lib</outputDirectory>
<resources> <resource> <directory>${settings.localRepository}/mysql/mysql-connector-java/5.1.6</directory>
<includes> <include>mysql-connector-java-5.1.6.jar</include> </includes>
</resource> </resources> </configuration> </execution> -->
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
Your filter properties rely on the ${env} parameter:
<filter>../src/main/filters/filter-${env}.properties</filter>
This parameter has no value in your "explode" profile. So Maven must be looking for:
../src/main/filters/filter-.properties
I suspect you were hoping it would be filter.properties and not filter-.properties.

Resources