Install Maven3 on Ubuntu 12.04

previously install Java.

jmprieto@dev-server:~$ cd
jmprieto@dev-server:~$ ll
total 28
drwxr-xr-x 3 jmprieto jmprieto 4096 may  3 19:33 ./
drwxr-xr-x 3 root     root     4096 may  3 19:25 ../
-rw------- 1 jmprieto jmprieto  286 may  3 19:46 .bash_history
-rw-r--r-- 1 jmprieto jmprieto  220 may  3 19:25 .bash_logout
-rw-r--r-- 1 jmprieto jmprieto 3486 may  3 19:25 .bashrc
drwx------ 2 jmprieto jmprieto 4096 may  3 19:26 .cache/
-rw-r--r-- 1 jmprieto jmprieto  675 may  3 19:25 .profile
jmprieto@dev-server:~$ pwd
/home/jmprieto
jmprieto@dev-server:~$ wget http://apache.rediris.es/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz
--2014-05-03 20:05:38--  http://apache.rediris.es/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz
Resolviendo apache.rediris.es (apache.rediris.es)... 130.206.1.5
Conectando con apache.rediris.es (apache.rediris.es)[130.206.1.5]:80... conectado.
Petición HTTP enviada, esperando respuesta... 200 OK
Longitud: 6927918 (6,6M) [application/x-gzip]
Grabando a: “apache-maven-3.2.1-bin.tar.gz”

100%[======================================================================================================================================================================>] 6.927.918   1,74M/s   en 3,6s    

2014-05-03 20:05:42 (1,83 MB/s) - “apache-maven-3.2.1-bin.tar.gz” guardado [6927918/6927918]

jmprieto@dev-server:~$ tar -zxf apache-maven-3.2.1-bin.tar.gz 
jmprieto@dev-server:~$ ll
total 6800
drwxr-xr-x 4 jmprieto jmprieto    4096 may  3 20:06 ./
drwxr-xr-x 3 root     root        4096 may  3 19:25 ../
drwxrwxr-x 6 jmprieto jmprieto    4096 may  3 20:06 apache-maven-3.2.1/
-rw-rw-r-- 1 jmprieto jmprieto 6927918 feb 22 09:27 apache-maven-3.2.1-bin.tar.gz
-rw------- 1 jmprieto jmprieto     286 may  3 19:46 .bash_history
-rw-r--r-- 1 jmprieto jmprieto     220 may  3 19:25 .bash_logout
-rw-r--r-- 1 jmprieto jmprieto    3486 may  3 19:25 .bashrc
drwx------ 2 jmprieto jmprieto    4096 may  3 19:26 .cache/
-rw-r--r-- 1 jmprieto jmprieto     675 may  3 19:25 .profile
jmprieto@dev-server:~$ sudo cp -R apache-maven-3.2.1 /usr/local
jmprieto@dev-server:~$ ll /usr/local/apache-maven-3.2.1/
total 48
drwxr-xr-x  6 root root  4096 may  3 20:06 ./
drwxr-xr-x 11 root root  4096 may  3 20:06 ../
drwxr-xr-x  2 root root  4096 may  3 20:06 bin/
drwxr-xr-x  2 root root  4096 may  3 20:06 boot/
drwxr-xr-x  3 root root  4096 may  3 20:06 conf/
drwxr-xr-x  3 root root  4096 may  3 20:06 lib/
-rw-r--r--  1 root root 14865 may  3 20:06 LICENSE
-rw-r--r--  1 root root   182 may  3 20:06 NOTICE
-rw-r--r--  1 root root  2513 may  3 20:06 README.txt
jmprieto@dev-server:~$ vi ~/.profile
jmprieto@dev-server:~$ exit
export JAVA_HOME="/usr/lib/jvm/java-6-openjdk"
export M2_HOME="/usr/local/apache-maven-3.2.1"
export M2="$M2_HOME/bin"
export PATH="$M2:$PATH"
jmprieto@dev-server:~$ java -version
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1ubuntu0.12.04.4)
OpenJDK Server VM (build 20.0-b12, mixed mode)
jmprieto@dev-server:~$ mvn -v
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T18:37:52+01:00)
Maven home: /usr/local/apache-maven-3.2.1
Java version: 1.6.0_27, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-6-openjdk-i386/jre
Default locale: es_ES, platform encoding: UTF-8
OS name: "linux", version: "3.11.0-15-generic", arch: "i386", family: "unix"
Install Maven3 on Ubuntu 12.04

Add license to Java source Maven project

from this project.

	<build>
		<plugins>
			<plugin>
				<groupId>com.mycila</groupId>
				<artifactId>license-maven-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
					<properties>
						<owner>Jose Manuel Prieto Palacios</owner>
						<email>josemanuel@prietopalacios.net</email>
					</properties>
					<excludes>
						<exclude>**/README</exclude>
						<exclude>**/*.launch</exclude>
						<exclude>**/*.xml</exclude>
						<exclude>**/*.properties</exclude>
						<exclude>**/*.txt</exclude>
						<exclude>src/test/resources/**</exclude>
						<exclude>src/main/resources/**</exclude>
					</excludes>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>check</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

Licenses:

  • AGPL-3
  • APACHE-2
  • BSD-2
  • BSD-3
  • BSD-4
  • GPL-3
  • LGPL-3
  • MIT
  • MPL-2
  • WTFPL
Add license to Java source Maven project

Maven Properties

You can use Maven properties in a pom.xml file or in any resource that is being processed by the Maven Resource plugin’s filtering features.
A property is always surrounded by ${ and }. For example, to reference the ${project.version} property

project.* Maven Project Object Model (POM). You can use the project.* prefix to reference values in a Maven POM.
settings.* Maven Settings. You use the settings.* prefix to reference values from your Maven Settings in ~/.m2/settings.xml.
env.* Environment variables like PATH and M2_HOME can be referenced using the env.* prefix.
System Properties: Any property which can be retrieved from the System.getProperty() method can be referenced as a Maven property.

The ${project.*} actually resolved to a MavenProject object. From there, you can just use bean properties to get the value you need
${project.basedir}
${project.groupId}
${project.version}

project.name and project.description
The name and project description can often be useful properties to reference from documentation. Instead of having to worry that all of your site documents maintain the same short descriptions, you can just reference these properties.
project.build.*
If you are ever trying to reference output directories in Maven, you should never use a literal value like target/classes. Instead you should use property references to refer to these directories.
project.build.sourceDirectory
project.build.scriptSourceDirectory
project.build.testSourceDirectory
project.build.outputDirectory
project.build.testOutputDirectory
project.build.directory

project.baseUri
If you need a valid URI for your project’s base directory, you can use the ${project.baseUri} property. If your project is stored in the directory /tmp/simple, ${project.baseUri} will resolve to file:/private/tmp/simple/.

Built-in properties

${basedir} represents the directory containing pom.xml
${version} equivalent to ${project.version} (deprecated: ${pom.version})

Pom/Project properties

${project.build.directory} results in the path to your “target” directory, this is the same as ${pom.project.build.directory}
${project.build.outputDirectory} results in the path to your “target/classes” directory
${project.name}refers to the name of the project (deprecated: ${pom.name} ).
${project.version} refers to the version of the project (deprecated: or ${pom.version}).
${project.build.finalName} refers to the final name of the file created when the built project is packaged

<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>
	...
	<build>
		<finalName>finalNameOfFile</finalName>
		...
	</build>		
</project>

Local user settings

${settings.localRepository} refers to the path of the user’s local repository

Environment variables

${env.M2_HOME} returns the Maven2 installation path.
${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
${java.home}../bin/java.exe

Java system properties

All Java System Properties defined by the JVM.

Custom properties in the POM

It’s not a good idea to use properties for artifact IDs. The ${project.file.parentFile.name} property cannot be resolved when using it as part of artifactId, however some properties do work (project.groupId for the artifactId seems to work).
However, this is not recommended. In fact, if you use any property for the artifact ID instead of a constant, you’ll get a warning when you build your project:

        <properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

${project.build.sourceEncoding}

Referencias:
books sonatype mvnref-book
MavenPropertiesGuide

Maven Properties

Maven instalar libreria en repositorio

mvn install:install-file -Dfile=ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar
mvn deploy:deploy-file -Durl=http://SERVIDOR/nexus/content/groups/public/ -DrepositoryId=NexusReleases -Dfile=ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -DgeneratePom=true -DgeneratePom.description="Oracle driver PROPIETARY." -DuniqueVersion=false

 

Maven instalar libreria en repositorio

Ejecucion de maven a traves de un script de windows

@ECHO OFF
REM -----------------------------------------------------------------------
REM Ejecucion del proceso maven: mvn clean package -Dmaven.test.skip=true
REM y se copia el war generado a la carpeta deploy de liferay
REM se hace uso de este script porque creo que es al ejecutar este comando
REM en eclipse cuando se me jode el invento
REM -----------------------------------------------------------------------

REM write to log file
ECHO # process START at %date% %time% --------------------------------- >> C:Proyectosdepoi-networkspace_branchpackageDeploy.log
ECHO Ejecutando: mvn clean package -Dmaven.test.skip=true
ECHO Ejecutando: mvn clean package -Dmaven.test.skip=true >> C:Proyectosdepoi-networkspace_branchpackageDeploy.log

set folder="C:Proyectosdepoi-networkspace_branchfacturaefacturae-portlets"
cd /d %folder%
call mvn clean package -Dmaven.test.skip=true >> C:Proyectosdepoi-networkspace_branchpackageDeploy.log
ECHO Exit Code = %ERRORLEVEL% > nul
if "%ERRORLEVEL%" == "0" echo "El Proceso Maven(mvn clean package -Dmaven.test.skip=true) ha funcionado perfectamente" >> C:Proyectosdepoi-networkspace_branchpackageDeploy.log
if not "%ERRORLEVEL%" == "0" echo "ERROR al ejecutar:mvn clean package -Dmaven.test.skip=true" >> C:Proyectosdepoi-networkspace_branchpackageDeploy.log

if "%ERRORLEVEL%" == "0" echo ...ACIERTO
if not "%ERRORLEVEL%" == "0" echo ...ERROR

ECHO Ejecutando: la copia del war a la carpeta deploy de liferay
ECHO Ejecutando: la copia del war a la carpeta deploy de liferay >> C:Proyectosdepoi-networkspace_branchpackageDeploy.log

set folder="C:Proyectosdepoi-networkspace_branchfacturaefacturae-portletstarget"
cd /d %folder%
set source=C:Proyectosdepoi-networkspace_branchfacturaefacturae-portletstargetfacturae-portlets-0.1.0-SNAPSHOT.war
set destination=C:Softwareliferayliferay-portal-6.1.1-ce-ga2deploy
xcopy %source% %destination% >> C:Proyectosdepoi-networkspace_branchpackageDeploy.log

ECHO Exit Code = %ERRORLEVEL% > nul
if "%ERRORLEVEL%" == "0" echo ...ACIERTO >> C:Proyectosdepoi-networkspace_branchpackageDeploy.log
if not "%ERRORLEVEL%" == "0" echo ...ERROR >> C:Proyectosdepoi-networkspace_branchpackageDeploy.log

if "%ERRORLEVEL%" == "0" echo ...ACIERTO
if not "%ERRORLEVEL%" == "0" echo ...ERROR

ECHO # process END --------------------------------------------------- >> C:Proyectosdepoi-networkspace_branchpackageDeploy.log

timeout /T 5
exit

Guardar como: packageAndDeploy.bat
Ejecutar como:
– con el raton pinchar dos veces
– en la consola de windows, (ir hasta el directorio que contiene el fichero), ejecutar: packageAndDeploy

Ejecucion de maven a traves de un script de windows