Saturday Aug 31

Key Concepts

Maven

AddThis Social Bookmark Button

Maven Tutorials on Java Tutorials

Maven
is a software tool for project management and build automation.

While primarily used for Java programming, it can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. Maven serves a similar purpose to the Apache Ant tool, but it is based on different concepts and works in a profoundly different manner.

Maven is hosted by the Apache Software Foundation, where it was formerly part of the Jakarta Project. Maven uses a construct known as a Project Object Model (POM) to describe the software project being built, its dependencies on other external modules and components, and the build order. It comes with pre-defined targets for performing certain well-defined tasks such as compilation of code and its packaging.

Maven dynamically downloads Java libraries and Maven plugins from one or more repositories. Maven provides built-in support for retrieving files from the Maven 2 Central Repository and other Maven repositories, and can upload artifacts to specific repositories after a successful build.

A local cache of downloaded artifacts acts as the primary means of synchronizing the output of projects on a local system. Maven is built using a plugin-based architecture that allows it to make use of any application controllable through standard input.

Theoretically, this would allow anyone to write plugins to interface with build tools (compilers, unit test tools, etc.) for any other language. In reality, support and use for languages other than Java has been minimal. Currently a plugin for the .Net framework exists and is maintained, and a C/C++ native plugin is maintained for Maven 2 maven-native and maven-nar

Source : Wikipedia

Last Updated on Wednesday, 13 July 2011 13:08
PDFPrintE-mail
Wednesday, 13 July 2011 12:35
AddThis Social Bookmark Button

Maven command line options

The command line options can be obtained with:

mvn --help.

Command line options

optionDescription
-q,--quiet Quiet output - only show errors
-C,--strict-checksums Fail the build if checksums don't match
-c,--lax-checksums Warn if checksums don't match
-P,--activate-profiles Comma-delimited list of profiles to activate
-amd,--also-make-dependents If project list is specified, also build projects that depend on projects on the list
-ff,--fail-fast Stop at first failure in reactorized builds
-rf,--resume-from Resume reactor from specified project
-fae,--fail-at-end Only fail the build afterwards; allow all non-impacted builds to continue
-B,--batch-mode Run in non-interactive (batch) mode
-am,--also-make If project list is specified, also build projects required by the list
-fn,--fail-never NEVER fail the build, regardless of project result
-emp,--encrypt-master-password Encrypt master security password
-ep,--encrypt-password Encrypt server password
-up,--update-plugins Synonym for cpu
-N,--non-recursive Do not recurse into sub-projects
-npr,--no-plugin-registry Don't use ~/.m2/plugin-registry.xml for plugin versions
-gs,--global-settings Alternate path for the global settings file
-U,--update-snapshots Forces a check for updated releases and snapshots on remote repositories
-cpu,--check-plugin-updates Force upToDate check for any relevant registered plugins
-npu,--no-plugin-updates Suppress upToDate check for any relevant registered plugins
-V,--show-version Display version information WITHOUT stopping build
-D,--define Define a system property
-X,--debug Produce execution debug output
-e,--errors Produce execution error messages
-f,--file Force the use of an alternate POM file.
-h,--help Display help information
-o,--offline Work offline
-pl,--projects Build specified reactor projects instead of all projects
-r,--reactor Dynamically build reactor fromsubdirectories
-s,--settings Alternate path for the user settings file
-v,--version Display version information
 
Last Updated on Tuesday, 02 April 2013 07:59
PDFPrintE-mail
Wednesday, 13 July 2011 12:23
AddThis Social Bookmark Button

Resolution will not be reattempted Maven

If you get the following error when you try to retrieve an artifact from your Nexus server. You probably try to hit an artifact from a third party repository not configured. The problem occurs when you have added the missing third party repository and you retry to run Maven but it still complain that the resolution will not be reattempted:

Failure to find <artifact> in http://<your nexus url> was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced

To fix this situation you have two options : 

  • Run Maven using -U 

-U,--update-snapshots Forces a check for updated releases and snapshots on remote repositoriey

  • Delete the corresponding groupId folder in your local repository

If you have any remark or questions feel free to put a comment.If you enjoyed this tutorial and want to promote it don't hesitate to click on



Last Updated on Friday, 15 March 2013 14:04
PDFPrintE-mail
Tuesday, 28 June 2011 12:28
AddThis Social Bookmark Button

Sometimes you are behind a proxy but you don't know the configuration details. You customer is using a Web Proxy Autodiscovery Protocol (aka WPAP). 

In internet Explorer or Firefox you probably have the Automatic detects settings checked in your configuration. In the other hand you have Maven who wants to access the internet to download the plugins and libraries. In the following tutorial, i will give you a step by step tutorial to configure your Maven settings.xml file to use the proxy settings

Retrieve the actual settings behind the Proxy Auto-Config (PAC)

Before fetching its first page, your favorite web browser implementing the auto configuration sends the local DHCP server a DHCPINFORM query, and uses the URL from the WPAD option in the server's reply. If the DHCP server does not provide the desired information, DNS is used.

If, for example, the network name of the user's computer is station.department.branch.ubiteck.com, the browser will try the following URLs in turn until it finds a proxy configuration file within the domain of the client:

  1. http://wpad.department.branch.ubiteck.com/wpad.dat 
  2. http://wpad.branch.ubiteck.com/wpad.dat
  3. http://wpad.ubiteck.com/wpad.dat 
  4. http://wpad.com/wpad.dat 

After having downloaded this file you should see something like that inside :

wdap.dat sample proxy configuration

function FindProxyForURL(url, host) {
// If URL has no dots in host name, send traffic direct.
    if (isPlainHostName(host))
        return "DIRECT";
// If specific URL needs to bypass proxy, send traffic direct.
    if (shExpMatch(url,"*domain.com*") ||
        shExpMatch(url,"*vpn.domain.com*"))                  
        return "DIRECT";
// If IP address is internal or hostname resolves to internal IP, send direct.
    var resolved_ip = dnsResolve(host);
    if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
        isInNet(resolved_ip, "172.16.0.0",  "255.240.0.0") ||
        isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
        isInNet(resolved_ip, "127.0.0.0", "255.255.255.0"))
        return "DIRECT";
                    
// If not on a internal/LAN IP address, send traffic direct.
    if (!isInNet(myIpAddress(), "10.10.1.0", "255.255.255.0"))
        return "DIRECT";
// All other traffic uses below proxies, in fail-over order.
    return "PROXY 1.2.3.4:8080; PROXY 4.5.6.7:8080; DIRECT";
    
}

The most important information is the proxy information returned at line 21 :

return "PROXY 1.2.3.4:8080; PROXY 4.5.6.7:8080; DIRECT";

You have two proxy addresses with there corresponding port. In our configuration example we will take those addresses to illustrate the maven configuration

Configure Maven according to the Automatic detects settings of your browser

You have know the primary and secondary proxy ip addresses and ports. We are know able to configure the proxy in our Maven settings.xml file.

Include the following snippet in the <proxies> section of your settings.xml-file:

proxy maven settings example

<settings>
  ...
  <proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>1.2.3.4</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
    </proxy>
  </proxies>
  ....
</settings>

The <proxy> element contains informations required to a proxy settings.

ElementTypeDescription
active boolean Whether this proxy configuration is the active one.
Default value is: true.
protocol String The proxy protocol.
Default value is: http.
username String The proxy user.
password String The proxy password.
port int The proxy port.
Default value is: 8080.
host String The proxy host.
nonProxyHosts String The list of non-proxied hosts (delimited by |).
id String No description.
Default value is: default.

If your proxy requires a user name and password you can add it in the proxy section. The nonProxyHosts setting accepts wild cards, and each host not to proxy is separated by the | character. This matches the JDK configuration equivalent.

Source : Configuring a proxy

You are now able to download plugins and artifacts from your favorite repository.

If you have any remark or questions feel free to put a comment.If you enjoyed this tutorial and want to promote it don't hesitate to click on </p>

Last Updated on Wednesday, 25 April 2012 13:52
PDFPrintE-mail
Friday, 24 June 2011 15:18
AddThis Social Bookmark Button

Maven-site-plugin problems

If you are facing problems generating maven site with the maven-site-plugin using Maven 3 you have to upgrade to version 3 of Maven Site plugin

vmn site created only css and images

mvn site call only creates css and images in your target/site folder

mvn site call create only images and css solution If you are using Maven 3 or later you should upgrade your maven site to the 3.0-beta-3 at least
 

Update your maven site plugin of your project's pom.xml-file with the following parameters :

Maven plugin configuration
        
             GroupId :     org.apache.maven.plugins
             ArtifactId :    maven-site-plugin
             Version :      3.0
              
Last Updated on Thursday, 16 June 2011 16:43
PDFPrintE-mail
Thursday, 09 June 2011 13:03
AddThis Social Bookmark Button

Ignore Eclipse files in subversion for Maven projects

When  you are using Maven and Eclipse you can use the Maven Eclipse plugin to materialize the project from a Maven POM. The files created are then derived from the pom and should not be persisted in Subversion. If you do that you will have discrepancies between the configuration defined in your POM. You can find below two methods to prevent this.

Ignore Eclipse artifacts using Subsclipse

If you want to ignore the Eclipse artifacts in Subversion you should click on 

Right Click -> Team  - > Set Property

Ignore Maven generateed files for Eclipse

Then you should enter the following property value : 

target
.classpth
.settings
.project
.wtpmodules

Ignore Eclipse artifacts using svn commands

Open a shell prompt. Change the path to your root project directory

Spring java source

$ svn propset svn:ignore 'target .classpath .settings .project .wtpmodules' .
$ svn commit -m"remove eclipse artifacts" .

Page 2 of 5

Java Tutorial on Facebook