Java Means Durgasoft: DURGA SOFTWARE SOLUTIONS, 202 HUDA Maitrivanam, Ameerpet, Hyd. PH: 040-64512786
Java Means Durgasoft: DURGA SOFTWARE SOLUTIONS, 202 HUDA Maitrivanam, Ameerpet, Hyd. PH: 040-64512786
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
1
JAVA Means DURGASOFT
Maven2
Index
Invoking Maven
Creating a new Project (jar)
Creating a new Project (war)
Standard Project Structure
directory description
o Compiling
o Running Unit Tests / Code Coverage
Packaging (jar, war)
Installing Artifact in Local Repository
Installing 3rdParty jar in local Repository
Cleaning Up
Creating Eclipse Project Structure
Maven Project file (pom.xml)
Adding Dependencies
Adding Developers
Setting Compiler Version
Usage:
o Using Profiles by OS
Web-Development
o Integration-Test with tomcat
o Online web-development with Jetty plugin
o Online web-development and automatic deployment with tomcat plugin
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
2
JAVA Means DURGASOFT
Invoking Maven
General Syntax:
mvnplugin:target[-Doption1 -Doption2 dots]
mvn help
mvn -X ...
Prints help debugging output, very useful to diagnose
Creating a new Project (jar)
mvnarchetype:create -DgroupId=Artifact Group
-DartifactId=Artifact ID
Example:
mvnarchetype:create -DgroupId=de.focusdv.bcs
-DartifactId=new-app
Creates a new Project Directory new-app with package structure de.focusdv.bcs.
Name of the packaged jar will be new-app-version.jar
mvnarchetype:create
-DgroupId=Artifact Group
-DartifactId=Artifact ID
-DarchetypeArtifactId=maven-archetype-webapp
Example:
mvnarchetype:create
-DgroupId=de.focusdv.bcs
-DartifactId=new-webapp
-DarchetypeArtifactId=maven-archetype-webapp
Creates a new Directory new-webappwith package structure de.focusdv.bcs.
Name of the packaged war will be new-app-version.war
directory description
Compiling
mvn compile
Running Unit Tests / Code Coverage
mvn test
compiles and runs unit tests
mvn clean cobertura:cobertura
generates a code-coverage report for the tests. It only works, if the pom.xml is configured as
follows:
</project>
…
<build>
<plugins>
…
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
…
</plugins>
</build>
…
<reporting>
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
4
JAVA Means DURGASOFT
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
…
</project>
mvninstall:install-file -Dfile=foo.jar
-DgroupId=org.foosoft -DartifactId=foo
-Dversion=1.2.3 -Dpackaging=jar
Cleaning Up
mvn clean
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
5
JAVA Means DURGASOFT
(see above).
Adding Dependencies
<project>
…
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>1.2.6</version>
</dependency>
…
</dependencies>
Because of ,junit will not be included in final packaging.
Adding Developers
<project>
…
<developers>
<developer>
<id>Baier</id>
<name>Hans Baier</name>
<email>hans.baier::at::focus-dv.de</email>
<organization>focus DV GmbH</organization>
<roles>
<role>Developer</role>
</roles>
</developer>
…
</developers>
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
6
JAVA Means DURGASOFT
</build>
Creating Assemblies
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory></outputDirectory>
<unpack>true</unpack>
<scope>runtime</scope>
<excludes>
<exclude>junit:junit</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
The second descriptor packages the program:
<assembly>
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/assembly/files</directory>
<outputDirectory></outputDirectory>
<includes>
<include>**/*.bat</include>
<include>**/native/**</include>
<include>**/*.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>target</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Supplementary files in this example are in
src/main/assembly/files.
This includes the program starter (.bat), native libraries (/native) and Properties files.
Packaging is invoked by:
mvnassembly:assembly
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
8
JAVA Means DURGASOFT
Using Profiles
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
9
JAVA Means DURGASOFT
Usage:
mvn -Prelease-profile clean assembly:assembly
or
mvn -Pdemo clean assembly:assembly
Using Profiles by OS
In this example we want to use the Linux SWT Libraries on Linux and the Windows libs on
Windows:
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>swt</groupId>
<artifactId>swt-win32</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
</profile>
<profile>
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
10
JAVA Means DURGASOFT
<id>unix</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>swt</groupId>
<artifactId>swt-linux-gtk</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
</profile>
</profiles>
<project>
…
<scm>
<developerConnection>
scm:svn:https://svnhost.net/svnroot/trunk/new-app
</developerConnection>
</scm>
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<tagBase>
https://svnhost.net/svnroot/tags
</tagBase>
</configuration>
</plugin>
…
</plugins>
</build>
Versioning
Keep the Verision of your POM artifact in the form version-SNAPSHOT until you release.
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
11
JAVA Means DURGASOFT
This assumes that a machine myhostexists with a configured and running Web-Server and
SSHServer
<repositories>
<repository>
<id>focus-repository</id>
<name>Focus BCS Repository</name>
<url>http://myhost/mvn/repository</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>focus-repository</id>
<name>Focus BCS Repository</name>
<url>scp://myhost/var/www/mvn/repository/</url>
</repository>
</distributionManagement>
Preparing Releases
Make sure, the SCM settings in the POM are correct and all changes are committed to the
SCM.
Then execute
mvn -Dusername=USER -Dpassword=PASS release:prepare
Before issuing the above command use it with -DdryRun=true first
tags in configured build profiles in the pom.xml
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
12
JAVA Means DURGASOFT
Performing Releases
mvn -P profile -Drelease:perform
Checks out the released version from tag in repository, builds, tests, packages and installs
package,
javadoc and sources in repository. As preparing the release removes activation tags from
build
profiles, it is necessary to supply the profile or the release will fail.
Web-Development
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
13
JAVA Means DURGASOFT
</execution>
</executions>
</plugin>
</plugins>
</build>
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
14
JAVA Means DURGASOFT
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
15
JAVA Means DURGASOFT
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786
16