Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Thursday, September 10, 2015

How to install Maven on CentOS

Steps to install and configure Maven on CentOS

  • Download the tar.gz file from Apache Maven site
  • Untar the file at some location (Eg: /opt/maven)
    • tar xzf <filename>
  • Add the environment variable to ~/.bash_profile file
    • cd $HOME
    • vi ~/.bash_profile
      • Append PATH variable with maven path
      • Add M2_HOME variable
      • export M2_HOME
    • Save and restart your system


  • Verify maven installation
    • mvn --version

Friday, February 20, 2015

How to generate JavaDoc jar using Maven

The maven-javadoc plugin can be used to generate a javadoc jar file, It uses JDK's javadoc.exe tools to generate javadocs, pack in jar file and deploy along with your project.
To add support of javadoc in your Maven, Just add 'maven-javadoc' plugin into your pom.xml file and specify goal as 'jar'.
Example :
<!-- Generates JAVADOC -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
Run it as mvn:install or mvn:package, It will generate javadoc and package it as a jar file.

Reference:



     

Tuesday, November 11, 2014

How to execute maven goal on parent module but not on childer

I am working on multi module maven project and If I define any plugin in the parent pom.xml file, It get executed for all the child build as well.

In simple language, I wanted to use one plugin in parent pom.xml file which read properties file from the base directory but whenever I executes it, all the sub pom.xml tries to read the properties file from their base directory and its ends up in maven failed.

To resolve the above issue, We just need to add "inherit' attributes in the plugin.

Example :

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<inherited>false</inherited>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/rpm.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>

Now the plugin will get executed from the parent pom.xml file.

Thank you :)

Wednesday, July 16, 2014

How to exclude properties file from the Jar file

Problem Statement : Suppose your are working on Java Project which uses Maven structure where your source code is under “/src/main/java” and all your configuration files like .properties file or xml file are under “/src/main/resources” and as a final build your final package is a jar but you want without few files from your classpath. Be default Maven plugin adds all the file which comes under resources in jar file.

Solution : You can achieve the above task by using maven-jar-plugin as follows :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <excludes>
            <exclude>**/otp.properties</exclude>
        </excludes>
    </configuration>

</plugin>

Tuesday, July 1, 2014

maven-dependency-plugin (goals “copy-dependencies”, “unpack”) is not supported by m2e

Recently While importing one Maven project into Eclipse(Juno, m2e plug-ins is already installed in Eclipse). I was getting one error in project : maven-dependency-plugin (goals “copy-dependencies”, “unpack”) is not supported by m2e


Reason: Eclipse m2e does not support execution, by copying the below code in the build tag resolve the issue.

Example:

<build>
<COPY_CODE_HERE>
</build>

Code :

<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>

<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-antrun-plugin
</artifactId>
<versionRange>
1.7
</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>

Save the project and it will resolve the issue, if not then Right click on your project and update Maven(Maven → Update Project... ).


Thursday, October 17, 2013

How to create Spring MVC project using Maven and Eclipse


This blog will show you how quickly you can  create a Spring MVC project and get it up and running, using the Maven archetype called spring-mvc-archetype.

Note: First You should verify that the Maven Integration for FTP is already installed in your eclipse, If not first installed and then create a new project.

Steps :
  • In Eclipse IDE, Goto  File > New > Project
  • Select Maven > Maven Project and click Next.
  • Make sure you don’t check the option Create a simple project (skip archetype selection), and click Next. In the next screen,
  • Select Catalog as All Catalogs, Archetype as spring-mvc into the Filter  and select maven-archetype-webapp in the artifact list as shown below :

 

In case, If you don't see the above artifact in your Archtype then Click on "Add Archetype" and Add :
    • Archetype Group Id: co.ntier
    • Archetype Artifact Id: spring-mvc-archetype
    • Archetype Version: 1.0.2
    • Repository URL: http://maven-repository.com/artifact/co.ntier/spring-mvc-archetype/1.0.2\
     
Click Next and Enter Group Id (e.g. Test), Artifact Id (e.g. Test), Version (e.g. 1.0) and Package (com.waheed.test), as shown below :

Click Finish.Finally you have a project structure looks like below:                         

 

Friday, January 18, 2013

What is Maven repository ?

Maven Repository :


A repository is a place where all the project jars, library jar, plugins or any other project specific artifacts are stored and can be used by Maven easily.

There are three types of repository :
  •  local
  • central
  • remote 

Local Repository :


The maven local repository is a local folder that is used to store all your project’s dependencies (plugin jars and other files which are downloaded by Maven). In simple, when you build a Maven project, all dependency files will be stored in your Maven local repository.

The default name of the Maven's local repository is .m2.

Central Repository

Maven central repository is repository provided by Maven community. It contains a large number of commonly used libraries.

When you build a Maven’s project, Maven will check your pom.xml file, to identify which dependency to download. First, Maven will get the dependency from your local repository, if not found, then get it from the default Maven central repositoryhttp://repo1.maven.org/maven2/

This repository is managed by Maven community, required to be configured and it requires internet access to be searched.

Remote Repository


Sometime, Maven does not find a mentioned dependency in central repository as well then it stopped build process and output error message to console. To prevent such situation, Maven provides concept of Remote Repository which is developer's own custom repository containing required libraries or other project jars.

For example, using below mentioned POM.xml,Maven will download dependency (not available in central repository) from Remote Repositories mentioned in the same pom.xml.
<repositories>
<repository>
<id>JBoss repository</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>

Maven Dependency Search Sequence :

When we execute Maven build commands, Maven starts looking for dependency libraries in the following sequence:

Step 1 - Search dependency in local repository, if not found, move to step 2 else exit.
Step 2 - Search dependency in central repository, if not found, move to step 3 else exit.
Step 3 - Search dependency in remote repository or repositories, if not found then it is prompt error message else exit.

Wednesday, January 9, 2013

how to install MAVEN on linux

What is MAVEN ?

Read here : http://maven.apache.org/

Here are the steps to download and install Maven on linux :

Step 1 : Download the latest binary from the http://maven.apache.org/download.cgi.
             apache-maven-3.0.4-bin.tar.gz
Step 2 : Untar it using tar command.
              tar -zxvf /usr/local/apache-maven-3.0.4-bin.tar.gz
Step 3: Add Maven binary Path to the System Path i,e add in .bash_profile path
          $ cd $HOME
          $ vi ~/.bash_profile
Set PATH and M2_HOME as follows
M2_HOME=/usr/local/apache_maven-3.0.4
PATH=PATH=$PATH:$HOME/bin:/usr/local/apache_maven-3.0.4/bin
save the file by pressing esc : wq button

Note: Don't delete the previous PATH, Just append the M2_HOME path after :

Now save and close the file then logout and login back to see the effects, To confirm where the installation has done properly or not, check :
mvn --version
you will see following ouput :
Apache Maven 3.0.4 (r1232337; 2012-01-17 00:44:56-0800)
Maven home: /usr/local/apache-maven-3.0.4
Java version: 1.7.0_10, vendor: Oracle Corporation
Java home: /usr/local/jdk1.7.0_10/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.18-92.el5", arch: "amd64", family: "unix"


Congratulation... you are done here  :)


How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...