How can I deploy build to server with Apache Maven? - java

I have just started to use Apache Maven. Now I would like to make Maven to be able to make production and development enviroment deploys with one click. I'm using Eclipse (Springsource version) and I have Maven plugin installed. My server has tomcat and only thing needed for deployment is to overwrite old war with new one and server has SSH access.

Both the Tomcat Maven Plugin and the Maven2 Cargo Plugin support remote Tomcat deployments (assuming the manager application is available).
For the Tomcat Maven Plugin, see the Usage page, the configuration is pretty simple.
For the Maven2 Cargo Plugin, here is a sample configuration (for a remote container):
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.1-sr-1</version>
<configuration>
<wait>true</wait>
<container>
<containerId>tomcat6x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.tomcat.manager.url>[https://yourhost/manager]</cargo.tomcat.manager.url>
<cargo.remote.username>[username]</cargo.remote.username>
<cargo.remote.password>[password]</cargo.remote.password>
</properties>
</configuration>
<deployer>
<type>remote</type>
<deployables>
<deployable>
<groupId>[war group id]</groupId>
<artifactId>[war artifact id]</artifactId>
<type>war</type>
<properties>
<context>[optional root context]</context>
</properties>
<pingURL>[optional url to ping to know if deployable is done or not]</pingURL>
<pingTimeout>[optional timeout to ping (default 20000 milliseconds)]</pingTimeout>
</deployable>
</deployables>
</deployer>
</configuration>
</plugin>
</plugins>
</build>
And type mvn cargo:deploy.
Cargo is more powerful (because container agnostic) but also more complicated. For simple needs, I find that the Maven Tomcat Plugin is, well, simpler.

Try the Maven Cargo Plugin. This handles various versions of Tomcat, among other app servers. It can start and stop the server before/after deploying. It should also be able to deploy remotely, although I can't testify it with Tomcat.

If what you need is a file replacement over SSH, I would recommend antrun plugin for the task.
For other deployments, take a look at the great cargo plugin.

Related

skip certain modules during deploy in multi-module maven java project on appengine w/ appengine-maven-plugin

I have a multi-module maven java project. In the parent pom:
<modules>
<module>core</module>
<module>batch-worker</module>
<module>be</module>
<module>scheduler</module>
<module>migrations</module>
</modules>
Both the migrations and core modules aren't services I wish to deploy but just common packages used throughout all services.
When i attempt a deploy with mvn appengine:deploy, I receive goal execution failures because the core and migrations modules do not define an app.yaml as they are not deployable services.
How do I skip these and omit them from the deploy?
You can define your services in the maven plugin.
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>
<services>
<!-- Default service-->
<service>${project.build.directory}/${project.name}-${project.version}</service>
<!-- other service-->
<service>${project.parent.basedir}/other_module/target/other_module_finalName-${project.version}</service>
</services>
</configuration>
</plugin>
However, in the documentation the services are take into account only for start/stop command and not for deploy. I don't know if it works.
Let me know.

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>

How to run a multiple module project using Maven on NetBeans [duplicate]

I am new to maven. So I have a project with pom.xml file. So I ran that with maven and the build was successful. I have glassfish. Glassfish is already running separately. So now what is the next step to run the project with Glassfish? My IDE is eclipse.
You have to first tell Maven to build the WAR, check out this plugin for that: http://maven.apache.org/plugins/maven-war-plugin/.
Then you need to tell maven how to deploy to glassfish, you can either configure a Maven execution plugin to do this (see here: https://www.mojohaus.org/exec-maven-plugin/). Or you can look around for a custom plugin devoted to integrating maven with glassfish. This one looks promising, but I have not used it: http://maven-glassfish-plugin.java.net/.
Maven provides a lot of basic functionality out of the box, but most of the cooler stuff with build automation is done through plugins.
Update
Just updating to add a very simple Pom that will do a auto-deployment. Note: if you just run a "mvn clean install", with the packaging set to 'war', maven will build the .war file for you and place it in the target/ folder. You can take this and deploy it to glassfish manually if you just want to get started.
Below is part of a very simple pom that uses the Maven execution plugin to auto-deploy to glassfish as a function of the build:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
<configuration>
<executable>${path-to-asadmin-util}</executable>
<arguments>
<argument>deploy</argument>
<argument>--user=${username}]</argument>
<argument>--passwordfile=${password-file}</argument>
<argument>--host=localhost</argument>
<argument>--port=4848</argument>
<argument>target/${project.name}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
This basically just calls the deploy command on the glassfish asadmin utility[1]. You need to fill in the following variables:
${path-to-asadmin-util} --> this is the path to your asadmin utility
(normally in the glassfish_home/bin)
${username} --> glassfish admin username
${password-file} --> password file for logging into glassfish
admin[2]
${project.name} --> name of your war
If you want to get more complicated I suggest taking a look at this thread: GlassFish v3 and glassfish-maven-plugin (Mac).
[1] - http://docs.oracle.com/cd/E18930_01/html/821-2433/deploy-1.html#SJSASEEREFMANdeploy-1
[2] - http://docs.oracle.com/cd/E18930_01/html/821-2435/ghgrp.html#ghytn
Additonnaly, you should have a glance at this StackOverflow thread, dealing with maven deployement in glassifsh : https://stackoverflow.com/a/1836691/1047365.
For further understanding of Maven, you should REALLY read this (free) book : http://www.sonatype.com/books/mvnref-book/reference/. This is THE reference for Maven.
We can explain you what Maven is doing, producing, etc ... but Sonatype made a great work and you'll probably learn more reading it than we could ever do !
Regards.
I found this tutorial useful: http://tshikatshikaaa.blogspot.com/2012/05/introduction-to-maven-concepts-crash.html

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

deploy java maven project to ec2 with pallet?

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

Categories

Resources