deploy java maven project to ec2 with pallet? - java

I'm wondering exactly how I would set this up. I have a normal java/tomcat/mysql app, and I want to deploy to EC2. I'd like to use pallet to provision the box, configure it, and deploy my war there. I'm hoping I can do this via a maven plugin?
I guess my other option is to create a lein project and deploy the war using a relative path, but I'm hoping for the maven plugin...

I can't speak to the AWS and Pallet part of your question, but assuming you have a running tomcat instance you can use the Apache Cargo project directly from maven to deploy your app:
Here is a sanitized version of our cargo configuration:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<container>
<containerId>tomcat6x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.hostname>${tomcat.hostname}</cargo.hostname>
<cargo.servlet.port>8080</cargo.servlet.port>
<cargo.remote.username>$[tomcat.username}</cargo.remote.username>
<cargo.remote.password>${tomcat.password}</cargo.remote.password>
</properties>
</configuration>
<deployer>
<type>remote</type>
<deployables>
<deployable>
<groupId>com.mycompany</groupId>
<artifactId>MyWebApp</artifactId>
<type>war</type>
<pingURL>http://my.company.com/url</pingURL>
<pingTimeout>80000</pingTimeout>
<properties>
<context>ROOT</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</plugin>
You can then get this run with this command (set the relevant properties of course):
mvn -DskipTests package cargo:deploy
More information on Using Apache Cargo with Maven is here: http://cargo.codehaus.org/Maven2+Plugin+Getting+Started

Related

Hot deployment of JavaEE applications using Maven-Cargo pluin

I am using maven-cargo plugin for deployment of a very simple JavaEE application.
And I was able to run and deploy to jboss but the hot deployment of the class files and jsps is not working.
(By hot deployment I mean when I change my Java classes then the changes should be reflected in the application without the server being getting restarted.)
For understanding cargo, I went through their documentation:
https://codehaus-cargo.github.io/cargo/Maven2+plugin.html
and various other So links also :
maven - Failed to execute cargo:start
Maven2: Cargo plugin hot deployment & Jonas support
Deploy web application using Cargo plugin to remote server
But none of posts gives an adequate answer to the questions.
I am using following maven goals which I am using to run and deploy my application :
cargo:deploy
cargo:run
Following the configuration done in pom.xml :
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.7.7</version>
<configuration>
<container>
<containerId>jboss71x</containerId>
<type>installed</type>
<home>C:\softwares\jboss\jboss-eap</home>
</container>
<configuration>
<type>existing</type>
<home>C:\softwares\jboss\jboss-eap\standalone</home>
</configuration>
<deployer>
<type>installed</type>
</deployer>
<deployables>
<deployable>
<groupId>com.test</groupId>
<artifactId>test-demo</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
<version>7.0.2.Final</version>
</dependency>
</dependencies>
</plugin>

Is it possible to call a Maven target from a pom.xml?

I have a project my.group.id:my.art.id which has the following plugin defined:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<type>remote</type>
</container>
<deployables>
<deployable>
<groupId>my.group.id</groupId>
<artifactId>my.art.id</artifactId>
<type>war</type>
<properties>
<context>/my-root</context>
</properties>
</deployable>
</deployables>
</configuration>
</plugin>
</plugins>
</build>
In CLI, I deploy my WAR as following:
mvn cargo:deploy -Dcargo.user=... -Dcargo.password=...
I am now in the situation that I want to deploy my.group.id:my.art.id from another project pom.xml. This project is responsible for integration tests, I am spawning a Dockerized Tomcat container and need to deploy the WAR.
What is the best approach here?
Just copy/paste the plugin code as above
Execute Maven target cargo:deploy -Dcargo.user=... -Dcargo.password=... on my.group.id:my.art.id. Is it possible to call a Maven target from within a Maven build plugin? Will it spawn a child Maven process and wait for execution? Should I use the exec-maven-plugin plugin for this?

maven cargo deploy to war file fails to deploy as part of teamcity

The same deployment works correctly on windows, and on linux - but using teamcity and its built in maven I get an error. Local deploys, and the error is :
the container configuration directory
"/BuildAgent/work/68d4a71c8dc5cfd9/target/cargo/configurations/tomcat8x"
does not exist. Please configure the container before attempting to
perform any local deployment.
The relevant section of pom looks like this :
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.8</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<home>${env.CATALINA_HOME}</home>
</container>
<configuration>
<type>existing</type>
<home>${env.CATALINA_HOME}</home>
</configuration>
<deployables>
<deployable>
<groupId>com.myapp</groupId>
<artifactId>ROOT</artifactId>
<type>war</type>
<properties>
<context>${project.build.finalName}</context>
</properties>
</deployable>
</deployables>
<deployer>
<type>installed</type>
</deployer>
</configuration>
</plugin>
Have I missed a section of the pom that is required for ubuntu ? Does teamcity do something different to vanilla maven ? I am using same version of maven in both environments.
Does your deploy work when you perform it on linux machine outside TeamCity?
Is ${env.CATALINA_HOME} defined correctly?
My guess is that ${env.CATALINA_HOME} is pointing to the wrong place

how to deploy multiple wars using the tomcat plugin in maven

From the forums that I followed I tried some ways to find a way to deploy mutliple wars using tomcat plugin in maven but I could not succeed.
I created a third project and used three projects in order to deploy them but I have not done it. Could you please tell me way to do it ?
Best Regards
Alper Kopuz
Here is the pom.xml that I used :
<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>
tr.com.provus.pays
</groupId>
<artifactId>PAYSGroupProject</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>../PAYSWeb</module>
<module>../PAYSDashboard</module>
<module>../PAYSStaticWeb</module>
</modules>
<name>PAYSGroupProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>deploy</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
I guess you cannot use the tomcat plugin on a pom type project, try instead to configure the plugin into one of the war projects and include the others as webapp dependencies with something like that :
<configuration>
<webapps>
<webapp>
<contextPath>/PAYSWeb</contextPath>
<groupId>tr.com.provus.pays</groupId>
<artifactId>PAYSWeb</artifactId>
<version>${project.version}</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
<webapp>...</webapp>
</webapps>
</configuration>
Look also at this post (but unanswered)
Each webapp will need a different context root which is supplied to the tomcat7 maven plugin with the "path" value.
You will deploy each web app from its own POM independently. But since you have a pom type project that causes the others to build, you should be able to redeploy all three at once.
Note that there are two ways to deploy using this plugin:
You can deploy without the war. It just compiles the java files and deploys them directly to tomcat.
You can deploy the war. Maven will have to build the war and then it gets deployed to Tomcat. This is more like a production deployment and helps you verify the war will deploy correctly.
So. Move your plugin XML to each of the three "modules" pom files. They will have type 'war'. Then add this under configuration:
<path>paysWeb</path>
under the <configuration> tag for the first 'module'. Of course, you use the different names for the <path> for each of the 'module's.
There is more info here: http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/usage.html

Error when deploying site of a maven multi module project with FTP

I have a multi module project. When I launch mvn site:deploy, the deployment of the base module works fine, but it fails to create the directory of the module sites on the FTP server:
[INFO] Error uploading site
Embedded error: Required directory: '/myremoteftprepository/myproject-mymodule' is missing
When I create the missing directory by hand, it works fine, but I would like to avoid that. It is surprising that the deploy command do not create it. Do you how to force this directory creation? Is it a bug in the wagon-ftp plugin?
FYI, here is my POM:
<build>
<extensions>
<!-- Enabling the use of FTP -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0</version>
</extension>
</extensions>
</build>
I have chosen to include the javadoc with:
<reporting>
<plugins>
<!-- include javadoc in the site -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<show>public</show>
</configuration>
</plugin>
</plugins>
</reporting>
and
<distributionManagement>
<site>
<id>site</id>
<name>maven site</name>
<url>ftp://ftp.blabla.org/myremoteftprepository</url>
</site>
</distributionManagement>
and my settings.xml is good.
You should not launch the site:deploy goal, but rather the site-deploy Maven lifecycle phase e.g. like that
mvn clean install site-deploy
and also make sure that the latest version of your wagon transport is used (2.2).
Also for javadoc plugin you should configure it as reporting plugin under the configuration of the maven site plugin.
With the most recent version of wagon-ftp (2.2), it works.

Categories

Resources