Maven


Maven is a build tool for ex. ant

Common Problems and activities
Multiple jars
Spring framework and hibernate framework

What are jar are required for spring and hibernate.
Multiple jars
Dependencies jars and versions need to close. - Matching the right version.
Project Structure
Building, publishing and deploying.

http://maven.apache.org/

Recent release is 3.5.3 as on 2018-03-08. It requires minimum Java 7

Set the SYSTEM PROPERTIES 
M2_HOME=D:\XXX\Software\apache-maven-3.0.5  // ADD THE MAVEN FOLDER LOCATION.
PATH=D:\XXX\Software\apache-maven-3.0.5\bin; //ADD THE MAVIN BIN FOLDER

c:\> mvn -version

- create project structure, download the jar dependencies and build the s/w
  


Respository - maven talk to respository and get the information. machine needs to connect to internet and talk to respository.


mkdir myapp
cd myapp/

mvn archetype:generate

download the all the required plug-ins


1. enter the number project jar needs to download : 106
2. Select the version
3. groupId : packagename com.xxx.java
4. artifactID:MavenTestApplication (jar,war - building deployment)
5. version: 
6: Package:
Confirmation : Y


Choose com.graphaware.neo4j:graphaware-springmvc-maven-archetype version:
1: 2.0.3.6
2: 2.1.1.6
3: 2.1.2.7
4: 2.1.2.9
5: 2.1.3.10
6: 2.1.3.11
7: 2.1.3.14
8: 2.1.3.15
9: 2.1.4.17
10: 2.1.4.18
Choose a number: 10: 10
Downloading: http://repo.maven.apache.org/maven2/com/graphaware/neo4j/graphaware
-springmvc-maven-archetype/2.1.4.18/graphaware-springmvc-maven-archetype-2.1.4.1
8.jar
Downloaded: http://repo.maven.apache.org/maven2/com/graphaware/neo4j/graphaware-
springmvc-maven-archetype/2.1.4.18/graphaware-springmvc-maven-archetype-2.1.4.18
.jar (21 KB at 75.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/com/graphaware/neo4j/graphaware
-springmvc-maven-archetype/2.1.4.18/graphaware-springmvc-maven-archetype-2.1.4.1
8.pom
Downloaded: http://repo.maven.apache.org/maven2/com/graphaware/neo4j/graphaware-
springmvc-maven-archetype/2.1.4.18/graphaware-springmvc-maven-archetype-2.1.4.18
.pom (2 KB at 10.1 KB/sec)
Define value for property 'groupId': : org.xxx.java
Define value for property 'artifactId': : MavenTestApplication
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  org.xxx.java: :
Confirm properties configuration:
groupId: org.xxx.java
artifactId: MavenTestApplication
version: 1.0-SNAPSHOT
package: org.xxx.java
 Y: : y
[INFO] -------------------------------------------------------------------------
---
[INFO] Using following parameters for creating project from Old (1.x) Archetype:
 graphaware-springmvc-maven-archetype:2.1.4.18
[INFO] -------------------------------------------------------------------------
---
[INFO] Parameter: groupId, Value: org.xxx.java
[INFO] Parameter: packageName, Value: org.xxx.java
[INFO] Parameter: package, Value: org.xxx.java
[INFO] Parameter: artifactId, Value: MavenTestApplication
[INFO] Parameter: basedir, Value: D:\myapp
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: D:\myapp\MavenTestApplic
ation
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7:27.937s
[INFO] Finished at: Wed Nov 19 09:19:30 IST 2014
[INFO] Final Memory: 12M/58M
[INFO] ------------------------------------------------------------------------
D:\myapp>dir
 Volume in drive D has no label.
 Volume Serial Number is 6400-EF75

 Directory of D:\myapp

11/19/2014  09:19 AM    <DIR>          .
11/19/2014  09:19 AM    <DIR>          ..
11/19/2014  09:19 AM    <DIR>          MavenTestApplication
               0 File(s)              0 bytes



====

Cd mavenTestApplication

D:\myapp\MavenTestApplication>

pom.xml
src folder
  ||--> Main (development code)
  ||--> test (junit testing)


---- Start pom.xml----
<!--
  ~ Copyright (c) 2014 GraphAware
  ~
  ~ This file is part of GraphAware.
  ~
  ~ GraphAware is free software: you can redistribute it and/or modify it under the terms of
  ~ the GNU General Public License as published by the Free Software Foundation, either
  ~ version 3 of the License, or (at your option) any later version.
  ~
  ~ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  ~  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  ~ See the GNU General Public License for more details. You should have received a copy of
  ~ the GNU General Public License along with this program.  If not, see
  ~ <http://www.gnu.org/licenses/>.
  -->

<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>org.xxx.java</groupId>
    <artifactId>MavenTestApplication</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>Neo4j Spring MVC Maven Archetype</name>
    <description>Neo4j Spring MVC Maven Archetype</description>

    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <neo4j.version>2.1.4</neo4j.version>
        <spring.version>4.0.0.RELEASE</spring.version>
        <graphaware.version>2.1.4.18-SNAPSHOT</graphaware.version>
    </properties>

    <dependencies>

        <!-- GraphAware Framework -->
        <dependency>
            <groupId>com.graphaware.neo4j</groupId>
            <artifactId>common</artifactId>
            <version>${graphaware.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.graphaware.neo4j</groupId>
            <artifactId>api</artifactId>
            <version>${graphaware.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Spring Framework -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Neo4j -->
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>${neo4j.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Testing -->
        <dependency>
            <groupId>com.graphaware.neo4j</groupId>
            <artifactId>server-community</artifactId>
            <version>${graphaware.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.graphaware.neo4j</groupId>
            <artifactId>tests</artifactId>
            <version>${graphaware.version}</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <finalName>${project.name}-all-${project.version}</finalName>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <appendAssemblyId>false</appendAssemblyId>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

-----end ----

go to the pom.xml location

D:\myapp\MavenTestApplication>mvn compile
D:\myapp\MavenTestApplication>mvn package
D:\myapp\MavenTestApplication>java -cp target/MavenTestApp-1.0-SNAPSHOT.jar com.xxx.rain.App



Installed Maven local

MAVEN Repository
Archetype Info - different type of projects, proj structure
Dependency Info - dependent jars

mvn archetype:generate  // maven went to archetype info type of project doing. Default selection. It will create application. Create 

the directory structure. & pom.xml
Group Id and dependency, Artfict Id

mvn compile 
 download the depend jar from Maven Dependency info Repository.

Project template - Create Project structure
Build Folder Structure of the project 

archetype: generage
Archetype - what is project type
Group ID  - java package of new source code
Artifact ID - name of the war
version 
Package - jar/war/ear


Maven Build

build lifecycle
consist of phases 
  compile
  test (optional)
  package

Default behavior of phases

Build phases
Validate -> check pom.xml 
compile => convert to class
test -> run the test case
package -> all 3 phase execute then it will create package
integration-test
verify
install -> install package into the maven respository (.m2 or remote repository)
Deploy -  

myapp:\> mvn clean // remove the target and build package

dependency scope
provided -javax.servlet.*
compile - 
test - junit


Plug-ins -Web build and deployment in the container
  intergatre work folow
  plug-in tomcat
  plug-in jetty

Declare the plug-in in the pom.xml

dependencies tag are required for code
plug-ins tag are required maven to use for building

<build>
<plugins>
    <plugin>
       <groupId>org.mortbay.jetty</groupId>
       <artifactId>maven-jetty-plugin</artifacId>
       <version>6.1.10</version>
       <configuration>
  <scanIntervalSeconds>5</scanIntervalSeconds>
</configuration>
    </plugin>
</plugins>
<build>



mvn jetty:run

mvn <plugin>:what need to do


eclipse intergation mvn
mvn eclipse:eclipse
D:\Test\mywebapp>mvn eclipse:eclipse


apache-maven-3.0.5 webapp-j2ee14 remote id

mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 -DarchetypeGroupId=org.glassfish.jersey.archetypes -

DinteractiveMode=false -DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example -DarchetypeVersion=2.13

Comments

Post a Comment

Popular posts from this blog

Robotic Process Automation

WorkFusion

7 Rules of Success A.P.J Abdul Kalam