Wednesday, 5 September 2012

Using CARGO plugin in Maven building tool

Hello! Now, we will see how can we configure an application container with maven.

CARGO is the Codehaus plugin, integration with maven helps to deploy the artifacts to the container, start the application container and stop the application container and many more options. Below is the code snippet for configuration of JBoss 4.0.2 application server with the Maven.

Step: 1 - Add the below code snippet with in the <plugins></plugins> tag.
     <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.0</version>
               
                <configuration>
                    <!-- container configuration -->
                    <container>
                        <containerId>jboss4x</containerId>
                        <home>${app.server.home}</home>
                    </container>
                    <configuration>
                        <type>existing</type>
                        <home>${app.server.deploy.dir}</home>
                    </configuration>
                   
                    <!-- <deployer>
                        <type>installed</type>
                    </deployer>
                     -->
                    <deployables>
                        <deployable>
                          <groupId>com.company</groupId>
                          <artifactId>application</artifactId>
                          <type>war</type>
                        </deployable>
                    </deployables>
                   
                </configuration>
               
                <!-- executions of tasks by the cargo plugin -->
                <executions>
                    <execution>
                        <id>start-container</id>
                        <phase>start</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                   
                    <execution>
                        <id>stop-container</id>
                        <phase>stop</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
       </plugin>


In the above stated code snippet, apart from the Codehaus Cargo plugin information, container configuration, deploy-able items, deployer info and executions are mentioned.

Step: 2 - Add following code snippet as a part of <properties></properties> tag.
        <app.server.home><path-to-jboss>/jboss-4.0.2</app.server.home>
        <app.server.deploy.dir>${app.server.home}/server/default</app.server.deploy.dir>


Step: 3 - Command to deploy the artifacts to the application container.
mvn cargo:deploy

Step: 4 - Command to start the application container using maven.
mvn cargo:start

Step: 5 - Command to stop the application container using maven.
mvn cargo:stop

For more information on Cargo plugin, please visit here

How to push build artifacts to remote repository using Maven

Hello! After a bit long time, I am writing a post in this "Gyan of Java" blog. Today, we will look into few concepts of Apache Maven building tool. Have you ever come across a situation where you need to push build artifacts to a remote repository? Have you ever come across a situation where you need to push third party artifacts to a remote repository? Let's look into these now.


To answer first query, need to add a <distributionManagement> tag entries in the pom.xml of the application.

Step: 1

<!-- remote repository server info where artifacts would be pushed -->
<distributionManagement>
<repository>
<id>remoteRepo</id>
<name>Internal Nexus Repository</name>
<url>http://<remote host name>:<port name>/<remote repository path>/</url>
</repository>
</distributionManagement>


Also, need to below add entries in the settings.xml file located in M2_HOME directory.

Step: 2
   <servers>
<server>
<id>remoteRepo</id>
<username><username></username>
<password><password></password>
</server>
  </servers>


After doing these changes, build your app with following command:
mvn clean deploy

Regarding the later question, pushing third party artifacts whose pom.xml is not available, below is the code snippet.

Step: 3
mvn deploy:deploy-file -DgroupId=com.company.app -DartifactId=appName -Dversion=1.0 -Dfile=<path-to-file>/appName.jar -Dpackaging=jar -DrepositoryId=remoteRepo -Durl=http://<remote host>:<port no>/<remote repository path> -DgeneratePom=true

but before executing Step :3 command, please make sure to add entries in settings.xml file as mentioned in Step: 2