Maven
-
Upload
ravireddy76 -
Category
Documents
-
view
3.018 -
download
0
description
Transcript of Maven
Apache Maven
Apache Maven
This presentation to illustrate how to use maven for build scripts
It always difficult for developers where and how to start a simple example to understand to write maven script for the projects.
I try to show in this presentation how we can leverage the maven for build scripts.
If you unable to follow or understand the process, Please do contact me at below details.
E-mail: [email protected]
www.ravireddyjsf.blogspot.com
Ravi Reddy ([email protected])
Apache Maven
Java Project We start to build a simple jar for a Java project in Eclipse IDE
Create a simple MavenJavaDemo java project in the eclipse make sure your project structure (circled in red color) and build path should look similar shown in below figures.
Apache Maven
POM.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ravi-demos.com.maven.demo</groupId>
<artifactId>MavenJavaDemo</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Example for build script-Maven</name>
<description>Example to create a build script using maven</description>
<!-- Add Java 1.6 plugin -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Apache Maven
Web Application ProjectIn this tutorial we build a simple *.war file for a Web application project in Eclipse IDE
Create a simple MavenWebAppDemo java project in the eclipse make sure your project structure (circled in red color) and build path should look similar shown in below figures.
Apache Maven
POM.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion><groupId>ravi-demos.com.maven.demo</groupId><artifactId>MavenWebAppDemo</artifactId><packaging>war</packaging><name>Example for maven build script for web app</name><version>0.0.1-SNAPSHOT</version><description>Example for maven build script for web application</description>
<!-- Adding dependency jars required for the project. --><dependencies>
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.4</version> <scope>provided</scope>
</dependency></dependencies>
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration>
Apache Maven
<webResources> <resource>
<directory>${basedir}/src/main/java</directory><targetPath>WEB-INF/classes</targetPath> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.jsp</include> </includes>
</resource></webResources></configuration></plugin><plugin>
<artifactId>maven-compiler-plugin</artifactId><configuration>
<source>1.6</source><target>1.6</target>
</configuration></plugin></plugins></build></project>
Apache Maven
Enterprise (EAR) Application Project
In this tutorial we build a simple *.ear file for a Enterprise application project in Eclipse IDE Create a simple MavenEarDemo java project in the eclipse make sure your project structure (circled in red
color) and build path should look similar shown in below figures.
Apache Maven
POM.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion><groupId>ravi-demos.com.maven.demo</groupId><artifactId>MavenEarDemo</artifactId><packaging>ear</packaging><name>Example for maven build script for ear app</name><version>0.0.1-SNAPSHOT</version><description>Example for build script for ear application</description>
<!-- Adding dependency jars required for the project. --><dependencies>
<!-- Web module to be bundled in EAR --><dependency><groupId>ravi-demos.com.maven.demo</groupId><artifactId>MavenWebAppDemo</artifactId><version>0.0.1-SNAPSHOT</version><type>war</type></dependency>
<!-- EJB/Jar module to be bundled in EAR --><dependency><groupId>ravi-demos.com.maven.demo</groupId><artifactId>MavenJavaDemo</artifactId><version>0.0.1-SNAPSHOT</version><scope>provided</scope></dependency>
</dependencies>
Apache Maven
<build><plugins>
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-ear-plugin</artifactId>
<configuration><manifestFile>src/main/application/META-INF/MANIFEST.MF</manifestFile><earSourceDirectory>src/main/application/</earSourceDirectory><earSourceExcludes>META-INF/MANIFEST.MF</earSourceExcludes>
<modules><webModule><groupId>ravi-demos.com.maven.demo</groupId><artifactId>MavenWebAppDemo</artifactId><contextRoot>/MavenWebAppDemo-0.0.1-SNAPSHOT</contextRoot><bundleFileName>MavenWebAppDemo-0.0.1-SNAPSHOT.war</bundleFileName></webModule>
</modules></configuration></plugin><plugin><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.6</source><target>1.6</target></configuration></plugin>
</plugins></build></project>