Maven - Deploy WAR to a specific folder also - java

I need to know how to instruct maven to deploy a ROOT.war into /deployments folder while keeping the standard /src/main/webapp deployement directory.
Here is the profile that I need to deal with:
<profile>
<id>sdk</id>
<build>
<plugins>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${gae.version}</version>
<configuration>
<enableJarClasses>false</enableJarClasses>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${version.gwt}</version>
<executions>
<execution>
<!-- gwt:compile happens just before package phase -->
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<modules>
<!-- gwt module inherits Core gwt module therefore both will be gwt:compiled -->
<module>org.example.App</module>
</modules>
<logLevel>DEBUG</logLevel>
<!--<logLevel>WARN</logLevel>-->
<runTarget>index.html</runTarget>
<appEngineVersion>${gae.version}</appEngineVersion>
<!-- tell the gwt plugin that the webapp source resides in src/main/webapp -->
<webappDirectory>${webappDirectory}</webappDirectory>
<!-- tell the gwt plugin that dev mode should be run using the webapp that resides in target/${webappDirectory} -->
<hostedWebapp>${webappDirectory}</hostedWebapp>
<!-- Normally the gwt maven plugin executes dev mode using a builtin jetty server.
This config property instructs the gwt maven plugin to execute dev mode using the
jetty server supplied by the appengine sdk. -->
<server>com.google.appengine.tools.development.gwt.AppEngineLauncher</server>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Now, my app being deployed in Openshift I need to have this profile also:
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>OpenShift template</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Just putting the maven-war-plugin alonside with the gwt-maven-plugin doesn't work and web.xml is not being copied and so forth. So I need to modify the gwt-maven-plugin settings instead.
The question here now is
How to make the gwt-maven-plugin to also deploy similar to this
openshift profile? To deploy ROOT.war into the /deployments folder

Related

Change working directory for Maven failsafe pre-integration-test to find Spring configuration

We have a multi module Maven project with multiple executable projects inside.
The directory structure looks similar to this:
parent
+- module1
+-- src/main/resources/application.yml
+-- config/bootstrap.yml
+-- config/application-dev.yml
+-- config/application-prod.yml
+-- pom.xml
+- pom.xml
where application.yml are packaged default values that are not environment specific and all files in the config folder belongs to external configuration needed only for local development which is not part of the WAR file.
Now if I start the application or tests from the IDE it works as expected. Also, if I run Maven builds in module1 folder. However, if I try to build the parent project, the bootstrap.yml is not found which fails the build during the pre-integration-test phase.
I discovered that the working directory is set to the parent folder instead of module1 which seems to be the problem as Spring looks in . and ./config. If I duplicate the config folder to root, it works in all cases.
Is there any way to tell Maven failsafe to set the working directory to the module folder during pre-integration-test phase where the Spring Context looks for the configuration?
parent/pom.xml:
<project ...>
<properties>
<maven.version>3.0.0</maven.version>
<maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>2.20.1</maven-failsafe-plugin.version>
</properties>
<modules>
<module>module1</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<runOrder>alphabetical</runOrder>
<includes>
<include>**/*IntTest.java</include>
</includes>
<skipTests>${skipTests}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
parent/module1/pom.xml:
<project>
<parent>
...
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</plugins>
</build>
</project>
Ok, for some reason both <environmentVariables> and <systemProperties> in the <config> block of maven-failsafe-plugin does not work in combination with spring-boot-maven-plugin.
It appears that spring-boot plugin is responsible to create the (forked) JVM in the pre-integration-test phase because of this snippet:
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
I solved it by configuring the spring-boot-maven-plugin instead:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<workingDirectory>${basedir}</workingDirectory>
According to documentation ${basedir} should be the default but maybe it doesn't work with Maven multi-module projects.

maven scm plugin migration from SVN to GIT

I had a maven project structure including following projects
server
client
node
This is my module structure in main pom
<modules>
<module>server</module>
<module>node</module>
<module>help</module>
<module>client</module>
</modules>
I defined an automatic jar creation mechanism that runs on server machine. It checkouts code for each module, compiles, builds, etc. In each module, I defined maven scm blug in for checking out latest code for related module (Server, client , node).
For example, this is pom.xml for server side.
<scm>
<connection>scm:svn:https://ip/svn/repositoryName/trunk/projectName/server/src</connection>
<developerConnection>scm:svn:https://ip/svn/repositoryName/trunk/projectName/server/src</developerConnection>
</scm>
And this is profile for refreshing
<profile>
<id>environment-refresh-sources</id>
<activation>
<property>
<name>refreshSources</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
<configuration>
<username>maven.user</username>
<password>password</password>
<checkoutDirectory>${basedir}/src</checkoutDirectory>
</configuration>
<executions>
<execution>
<id>CheckoutFromSVN</id>
<phase>initialize</phase>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
We have this configuration for each module. Just scm connection is changing. For example: this is for client.
<connection>scm:svn:https://ip/svn/repositoryName/trunk/projectName/client/src</connection>
Now I am trying to migrate from SVN to GIT. But I am not able to configure maven plug in to work in this way.
This is my scm configuration for GIT.
<scm>
<connection>scm:git:http://maven.user#ip/scm/sig/project.git</connection>
<developerConnection>scm:git:http://maven.user#ip/scm/sig/project.git</developerConnection>
</scm>
This is my new plugin for git. I have added branch part. Now it checkouts master branch including server, client etc. modules. How can I work in same way with GIT.
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
<configuration>
<connectionType>developerConnection</connectionType>
<scmVersion>master</scmVersion>
<scmVersionType>branch</scmVersionType>
<username>maven.user</username>
<password>password</password>
<checkoutDirectory>${basedir}/src</checkoutDirectory>
</configuration>
<executions>
<execution>
<id>CheckoutFromGIT</id>
<phase>initialize</phase>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>

How to distinguish between different wsdl locations in one pom.xml - Maven

Is there a possibility to distinguish between multiple configurations of wsdl webservices in maven?
I have one application which can run on test, stage and prod environments. And I have to use one webservice. The webservice has 3 different wsdl locations. For test, stage and prod.
Is there a way in maven to say if I want to build my application for prod just use the webservice location for prod. And the same also for stage and test?
I have a wsdl import configuration which works fine for a single non-dynamical part.
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlFiles>
<wsdlFile>wsdlFile_live.wsdl</wsdlFile>
</wsdlFiles>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
<packageName>com.example.schema</packageName>
<wsdlLocation>http://liveLocation/?wsdl</wsdlLocation>
</configuration>
<id>wsimport-generate-_live.wsdl</id>
<phase>generate-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>webservices-api</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
<configuration>
<sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
<xnocompile>true</xnocompile>
<verbose>true</verbose>
<extension>true</extension>
<catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
</configuration>
Creating profiles in maven is one possibility to build different applications with different scopes.
<profiles>
<profile>
<id>prod</id>
<build>
....
</build>
</profile>
<profile>
<id>test</id>
<build>
....
</build>
</profile>
</profiles>
In the profile property you can set dependencies, resourves, plugins, configurations and so on.
To build a specific profile you have to type mvn -P followed by the profile ID
In my case it looks like this: mvn -Ptest clean install or mvn -Pprod clean install
You can use environment variables to store your wsdl file and pass to maven system properties. For example, say on Linux you want to access environment variable MY_VARIABLE. You can use a system property in your pom file.
<properties>
...
<!-- Default value for my.variable can be defined here -->
<my.variable>foo</my.variable>
...
...
${my.variable}
Set the property value on the maven command line:
mvn clean package -Dmy.variable=$MY_VARIABLE

Can I tailor a maven build based on platform?

Specifically, I run the launch4j-maven-plugin plugin to generate me an .exe file. This only works on Windows, so I was wondering if I could 'opt-out' of this step on other platforms?
The plugin is tied to the execution phase like this
<plugin>
...
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
</execution>
...
You can wrap that plugin under separate build profile and just enable that profile on the build that you want
For example:
<project>
...
<profile>
<id>generate-exe</id>
<build>
<plugins>
<plugin>
<!_- your plugin configuration -->
</plugin>
...
</plugins>
</build>
</profile>
...
</project>
Now pass parameter while launching maven to specify profile
For example:
mvn clean install -Pgenerate-exe

maven remote tomcat configuration

I am using maven2. I have tomcat7 installed. I want to configure the plugin to use tomcat7 that is installed. can somebody point to a link that does this.
Use Cargo plugin for this. Configure cargo something like this
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0</version>
<configuration>
<!-- Container configuration -->
<container>
<containerId>tomcat6x</containerId>
</container>
<configuration>
<type>existing</type>
<home>/usr/local/apache-tomcat-6.0.18</home>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
I have same setup, but I have tested this on Tomcat6.0.x and Jetty 7.0.16. These links will help
Automated deploy with Cargo
Cargo config for Tomcat 7
for remote deployment use like this (must not be different in Tomcat7)
<configuration>
<!-- Container configuration -->
<container>
<containerId>tomcat6x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.remote.username>admin</cargo.remote.username>
<cargo.remote.password></cargo.remote.password>
<cargo.tomcat.manager.url>http://localhost:8888/manager</cargo.tomcat.manager.url>
</properties>
</configuration>
...
</configuration>
Again refer the links above!

Categories