Mar 05, 10 by Juan Lebrijo about IT management, blog, Eclipse, Java
Siguiendo con nuestro objetivo de crear un entorno de desarrollo de software Extremo, hoy añadimos esta herramienta a la caja.
Maven es una herramienta de gestión de proyectos de software con las siguientes características:
Convención sobre configuración:provee de una serie de standards estructurales en los proyectos con el fin de homogeneizar la construcción de los mismos y ahorrar los quebraderos de cabeza de algunos sistemas de configuración.
${basedir}/src/main/java: para tu código
${basedir}/src/main/resources: para los ficheros de configuración
${basedir}/target/classes: para las clases java compiladas
${basedir}/target: los paquetes, jar, war, ear....
....
Maneja todos los hitos del ciclo de vida de un proyecto de software:
Ciclo de vida muy simple: Compilado --> Test --> Empaquetado
En cada hito del ciclo de vida se pueden ejecutar goals (objetivis). Por ejemplo en el empaquetado: mvn jar:jar
Controla las dependencias con otros proyectos: esta es la característica que me ha enganchado:
Olvídate de descargar los jars de spring, hibernate, configurarlas en el Java Buil Path,..... un rollo. Solución: marcas tus dependencias en el pom.xml, y el solito te las descarga y coloca en el Build path.
Los Arquetipoooos ¡¡¡¡ Son esqueletos de aplicación con pom.xml preconfigurados para hacer proyectos grails, seam, roo,... Échale un ojo a Appfuse y a los arquetipos cuando vayas a crear un nuevo proyecto maven en tu eclipse.
Ofrece un ecosistema de plugins para ejecutar todos los objetivos en las fases de cualquier proyecto.
Además en mi caso cumple unas características fundamentales:
Para abrir un poco boca haremos un pequeño ejemplo en nuestro eclipse. Para ello crearemos un nuevo proyecto File > New > Other ... > Maven > Maven Project. Marcamos "Create a simple project" para no seleccionar arquetipos. Maven te obliga a rellenar el Group Id, Artifact ID.
Podemos generar la siguiente clase de ejemplo:
package com.lebrijo.ejemploMaven;
public class Hello {
public static void main( String[] args ) {
System.out.println( "Hello World!" );
}
}
el comando "mvn install" nos generaría el jar que luego ejecutaríamos con "java -cp target/simple-1.0-SNAPSHOT.jar com.lebrijo.ejemploMaven.Hello". Pero en eclipse basta con ejecutar como Java Application.
Para añadir una dependencia, botón derecho sobre el proyecto Maven > Add dependencies:
mvn_search_dependencies.JPG61.3 KB
Podríamos utilizar la inyección de dependencias de Spring haciendo la búsqueda, incluso seleccionar la versión. Después de esto actualizamos las librerías con botón derecho sobre el proyecto > Maven > Update Dependencies.
Esta acción genera el siguiente trozo al pom.xml:
Mar 05, 10 by Juan Lebrijo about IT management, blog, Eclipse, Java
Following our target, create a XP Software Development Environment, today we add another tol for the box.
Maven is a project management tool with the following main features:
Convention over configuration: it provides many estructural standards for the project in order to make easy the development, and avoid problems with many configuration files:
Very simple Life Cycle: Compiling --> Test --> Packaging
In every life cycle steps you can execute goals. In packaging for example: mvn jar:jar
Manage the dependencies with other projects, this is the feature that takes my attention:
Forget download jar libraries for spring, hibernate, configure them in Java Buil Path,..... bad stuff. Solution: write your dependencies in pom.xml, and it download them and makes the Build path.
The Archetypeeeees ¡¡¡¡ They are application skeletons with preconfigured pom.xml to develop projects like grails, seam, roo,... Take a look at Appfuse and this archetypes when you will create a project with maven in eclipse.
Have a plugin ecosystem to execute goals for all the phases in every kind of project.
Furthermore in my case gives some fundamental features:
For the begining we are going to make an example with Eclipse. Create a new project File > New > Other ... > Maven > Maven Project. Mark "Create a simple project" to avoid archetypes now. Maven makes you fill Group Id, Artifact ID.
Create the following example Class:
The command "mvn install" generate the jar that we execute with "java -cp target/simple-1.0-SNAPSHOT.jar com.lebrijo.ejemploMaven.Hello". But in Eclipse you can execute as Java Application.
To add a dependency, right button over the project > Maven > Add dependencies:
mvn_search_dependencies.JPG61.3 KB
We could use the Spring dependency injection making the search, and select the concrete version. After thar we update the libraries with right clic over the project > Maven > Update Dependencies.
This actiion generates the followin pom.xml file:
Feb 25, 10 by Juan Lebrijo about UML, blog, Eclipse, Java
Eclipse has a project called EMF (Eclipse Modelling Framework) cool for drawing UML2 Diagrams. But my goal in this post is to draw UML2 class diagrams and create the java skeleton for the classes.
In the application architecture is recommended separate the domain model from services, business logic etc. EMF gives you the tool to create class diagrams and to generate the code with them.
We can install EMF plugins in our Eclipse installation, or download the Modelling Eclipse bound. I recommend the second choice because is cleaner, at least to test.
I left in the following link the final product of this post: Eclipse UML2 to code project.
An now !! the show must start¡¡:Create a new project: File > New > Project... > Empty EMF Project
In the model folder we creates: New > Other... > Ecore Tools > Ecore Diagram.
We draw our model using the palette, and Properties view:
clases.jpg29.9 KB
Is very intuitive to draw the diagram. In the association properties we put the numeral and mark "Is Containment" to do the composition association.
Now we are going to create a transition file .genmodel type. Select .ecore file from the diagram we want generate, and right button New > Other... > Eclipse Modeling Framework > EMF Generator Model.
In the file .genmodel we can generate the code as follows:
generar.jpg9.87 KB
and .... !!! BOILA ¡¡¡ we have three packages:
generated.thumbnail.jpg3.13 KB
Clicking in the last image you can see how ends the src folder:
classdiagram: Containing the model with interfaces in order to decouple the design.
classdiagram.impl: Model and Factory implementation to generate the classes.
classdiagram.util: AdapterFactory implementation.
Furthermore the implementation of the model, it generates code to implement Dependency injection with factories. The code has the JavaDoc comments, you will not forget write them.
Puts all the getters/setters defined in the class diagram.
Every methods annotated with @generated, if you don't wish the rewrote in the future you must delete the annotation.
To read more about it, and UML2 modeling with Eclipse, and many more Eclipse/Java stuff I recomend us the Vogella web (great site).