Difference between revisions of "Maven"

From BC$ MobileTV Wiki
Jump to: navigation, search
Line 183: Line 183:
 
* '''Maven -- central repository: https://search.maven.org (3.x) | [http://repo1.maven.org/maven2/ Maven 2.x]'''
 
* '''Maven -- central repository: https://search.maven.org (3.x) | [http://repo1.maven.org/maven2/ Maven 2.x]'''
 
* Maven - The Complete Reference (E-BOOK): http://www.sonatype.com/books/mvnref-book/reference/public-book.html
 
* Maven - The Complete Reference (E-BOOK): http://www.sonatype.com/books/mvnref-book/reference/public-book.html
 +
* Maven Cheat Sheet: https://zeroturnaround.com/rebellabs/maven-cheat-sheet/
 
* Coping with Sun JARs: http://maven.apache.org/guides/mini/guide-coping-with-sun-jars.html
 
* Coping with Sun JARs: http://maven.apache.org/guides/mini/guide-coping-with-sun-jars.html
 
* '''The Maven 2 POM demystified: http://www.javaworld.com/javaworld/jw-05-2006/jw-0529-maven.html'''
 
* '''The Maven 2 POM demystified: http://www.javaworld.com/javaworld/jw-05-2006/jw-0529-maven.html'''
Line 213: Line 214:
 
* '''How to create a Web Application Project with Maven: http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/'''
 
* '''How to create a Web Application Project with Maven: http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/'''
 
* How To Create A Java Project With Maven: www.javawebtutor.com/articles/maven/maven_java_project.php<ref>Code Sharing (amongst several team members)? Use Maven: https://pettermahlen.com/2010/05/01/code-sharing-use-maven/</ref>
 
* How To Create A Java Project With Maven: www.javawebtutor.com/articles/maven/maven_java_project.php<ref>Code Sharing (amongst several team members)? Use Maven: https://pettermahlen.com/2010/05/01/code-sharing-use-maven/</ref>
* '''How to convert Java web project to Maven based project: http://www.mkyong.com/maven/how-to-convert-java-web-project-to-maven-project/'''
+
* '''How to convert Java web project to Maven based project: http://www.mkyong.com/maven/how-to-convert-java-web-project-to-maven-project/'''<ref>Maven & Jenkins with Selenium: Complete Tutorial : https://www.guru99.com/maven-jenkins-with-selenium-complete-tutorial.html</ref>
 
+
  
  

Revision as of 12:04, 4 September 2017

Apache Software Foundation (ASF) logo
Apache Maven project

Maven is a dependency management system and build tool for rapid Java-based application development with rich features to streamline development and SCM. Maven is a Yiddish word which means "accumulator of knowledge". The Maven Project started out as an attempt to simplify build processes in a project with multiple Ant build scripts. It was proposed that a standard way to build projects, clearly define what a project consists of, easily publish project information and share JARs across several different projects would greatly simplify and lend efficiency and speed to the Java development process.


Phases

Although hardly a comprehensive list, these are the most common default lifecycle phases executed.

  • validate - validate the project is correct and all necessary information is available
  • compile - compile the source code of the project
  • test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package - take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test - process and deploy the package if necessary into an environment where integration tests can be run
  • verify - run any checks to verify the package is valid and meets quality criteria
  • install - install the package into the local repository, for use as a dependency in other projects locally
  • deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

There are two other Maven lifecycles of note beyond the default list above. They are

  • clean - cleans up artifacts created by prior builds
  • site - generates site documentation for this project

[1]

Build Commands

The following are some useful commands (don't forget to remove "mvn" before adding a command to a Run Configuration in your IDE of choice, the plugin will automatically call Maven).

Standard full clean & install (with complete maven repository building of dependencies via POM dependency list):

mvn clean install -PautoInstallPackage

Clean the target directory, build and explode out a WAR file, run it in an embedded Jetty server (should be configured properly in pom.xml).

mvn clean war:exploded jetty:run -e

Run unit tests:

mvn test

Package a runnable JAR, WAR or EAR:

mvn package

Build a new snapshot and release:

mvn -U deploy

An interesting thing to note is that phases and goals may be executed in sequence:

mvn clean dependency:copy-dependencies package



POM

In Maven, the Project Object Model (POM) is the term given to the XML-based definition of a project (similar to DOAP), which focuses on providing a listing of Dependencies (libraries, supporting tools, etc), where to download or obtain those Dependencies, and how to use those dependencies together with the code contained in the software project in order to successfully perform a Build. It also provides a linkage to Defect Management (aka. Issue Management) & Testing tools. The following is an empty template for the syntax of the POM file.

 <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>

  <!-- The Basics -->
  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>...</version>
  <packaging>...</packaging>
   <dependencies>
     <dependency>
       <groupId>...</groupId>
       <artifactId>...</artifactId>
       <version>...</version>
     </dependency>
   </dependencies>
   <parent>...</parent>
   <dependencyManagement>...</dependencyManagement>
   <modules>...</modules>
   <properties>...</properties>

  <!-- Build Settings -->
   <build>...</build>
   <reporting>...</reporting>

  <!-- Additional Project Information -->
   <name>...</name>
   <description>...</description>
   <url>...</url>
   <inceptionYear>...</inceptionYear>
   <licenses>...</licenses>
   <organization>...</organization>
   <developers>...</developers>
   <contributors>...</contributors>

   <!-- Environment Settings -->
   <issueManagement>...</issueManagement>
   <ciManagement>...</ciManagement>
   <mailingLists>...</mailingLists>
   <scm>...</scm>
   <prerequisites>...</prerequisites>
   <repositories>...</repositories>
   <pluginRepositories>...</pluginRepositories>
   <distributionManagement>...</distributionManagement>
   <profiles>...</profiles>
 </project>

Tools

Plugins

Continuous Integration

Continuous Integration

jUnit

SoapUI

Tomcat

Config processor

Castor

Exec (command-line)

CloudTools


Language Extensions

While just about any program can be run remotely in a cloud environment via the CloudTools plugin, or by calling a local program from the command-line via the Exec plugin, there are still instances when you want to work more closely with a given programming language's specific tools such as compilers, testing suites, IDEs, etc. You can accomplish this by using one of the many Language-specific Maven extensions.

PHP

Python

Flex

C#

C/C++

RubyScript


Resources


Tutorials


External Links


References

  1. Maven in 5 Minutes: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
  2. Native C/C++ Maven Plugin (usage):http://mojo.codehaus.org/maven-native/native-maven-plugin/usage.html
  3. How do I use Maven through a proxy?: https://stackoverflow.com/questions/1251192/how-do-i-use-maven-through-a-proxy
  4. m2eclipse wont download maven artifacts: http://stackoverflow.com/questions/3963439/m2eclipse-wont-download-maven-artifacts
  5. Unable to download jars using M2Eclipse (0.10.0, using Maven 3): http://stackoverflow.com/questions/3019811/unable-to-download-jars-using-m2eclipse-0-10-0-using-maven-3/
  6. NetBeans Platform Quick Start Using Maven: http://platform.netbeans.org/tutorials/nbm-maven-quickstart.html?intcmp=925655
  7. Maven 3 support in NetBeans IDE 7.0+: http://netbeans.dzone.com/articles/maven-3-support-in-netbeans-ide
  8. How to convert a Maven pom.xml into an Ivy ivy.xml file : http://stefan222devel.blogspot.com/2010/01/how-to-convert-maven-pomxml-into-ivy.html
  9. Convert Maven POM dependencies to ivy.xml file: http://stackoverflow.com/questions/3715811/maven-pom-dependencies-to-ivy-xml-file
  10. NetBeans Platform Maven Command Line Tutorial: http://platform.netbeans.org/tutorials/nbm-maven-commandline.html?intcmp=925655
  11. NetBeans Platform Quick Start Using Maven: https://platform.netbeans.org/tutorials/nbm-maven-quickstart.html
  12. Creating an Enterprise Application Using Maven
  13. NB - Convert a project to Maven?: https://forums.netbeans.org/topic55932.html
  14. Converting a Netbeans project to a Maven enabled project: https://stackoverflow.com/questions/5495213/converting-a-netbeans-project-to-a-maven-enabled-project
  15. How to Create Web Application using Maven and Netbeans: https://javapointers.com/tutorial/create-web-application-using-maven-and-netbeans/
  16. Add JDBC in Netbeans Maven Project: https://stackoverflow.com/questions/30947905/add-jdbc-in-netbeans-maven-project
  17. NetBeanws -- Testing a Maven Enterprise Application: https://netbeans.org/kb/docs/javaee/maven-entapp-testing.html
  18. Code Sharing (amongst several team members)? Use Maven: https://pettermahlen.com/2010/05/01/code-sharing-use-maven/
  19. Maven & Jenkins with Selenium: Complete Tutorial : https://www.guru99.com/maven-jenkins-with-selenium-complete-tutorial.html

See Also

Ant | Java | CI | Testing | SCM