java:maven
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
java:maven [2013/03/16 12:52] – rlunaro | java:maven [2022/12/02 21:02] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Notes on Maven ====== | ||
+ | |||
+ | ===== Intro ===== | ||
+ | |||
+ | |||
+ | Hi, these are my notes on Maven. Probably here are a lot of inaccuracies, | ||
+ | |||
+ | |||
+ | |||
+ | ===== Some notes of the Maven Architecture ===== | ||
+ | |||
+ | ==== Plugins and Goals ==== | ||
+ | |||
+ | Maven uses a lot of // | ||
+ | |||
+ | //Plugins// are jar files who make things for Maven. | ||
+ | |||
+ | Examples of plugins are: | ||
+ | |||
+ | * Archetype plugin | ||
+ | * Jar plugin | ||
+ | * Compiler plugin | ||
+ | * Test plugin (Surefire) | ||
+ | * Hibernate3 plugin | ||
+ | * jRuby | ||
+ | |||
+ | **Plugins have goals**. For example, the compiler plugin have the '' | ||
+ | |||
+ | ==== Maven lifecycle ==== | ||
+ | |||
+ | Every project has his lifecycle, which is of course configurable. There can be many. | ||
+ | |||
+ | This is the default lifecycle: | ||
+ | |||
+ | < | ||
+ | process-resources | ||
+ | | | ||
+ | + compile | ||
+ | | | ||
+ | + process-classes | ||
+ | | | ||
+ | + process-test-resources | ||
+ | | | ||
+ | + test-compile | ||
+ | | | ||
+ | + test | ||
+ | | | ||
+ | + prepare-package | ||
+ | | | ||
+ | + package | ||
+ | |||
+ | </ | ||
+ | |||
+ | Of course, **there is a correspondence between phases and goals**. Here are ilustrated some of them: | ||
+ | |||
+ | < | ||
+ | process-resources -------------------------> | ||
+ | | | ||
+ | + compile ------------------------------> | ||
+ | | | ||
+ | + process-classes | ||
+ | | | ||
+ | + process-test-resources -----> resources: | ||
+ | | | ||
+ | + test-compile ----------> | ||
+ | | | ||
+ | + test -------------> | ||
+ | | | ||
+ | + prepare-package | ||
+ | | | ||
+ | + package > jar:jar | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Getting Help ==== | ||
+ | |||
+ | You can get help from Maven itself. There is a plugin used to get help from the different goals available. | ||
+ | |||
+ | < | ||
+ | |||
+ | mvn help: | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== Migrating an existing project to maven ===== | ||
+ | |||
+ | These are my notes about migrating an existing, not mavenized project into maven. I've selected a project which is relatively simple: it only run as a batch program, it doesn' | ||
+ | |||
+ | Let's start with it. | ||
+ | |||
+ | I've created a new project with: | ||
+ | |||
+ | < | ||
+ | rluna@petrus: | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Some changes in the '' | ||
+ | |||
+ | The version of this project is currently the 3.0. If I succeeded, I rather prefer to have it in the version 4.0: mostly because it is more than probable that many changes will be made, including changes in the structure of directories, | ||
+ | |||
+ | I've changed the version: | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | The name, website and other details: | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | Another Majordomo in Java | ||
+ | |||
+ | JNestor is a software developed in java whose | ||
+ | main purpose is to read a mailbox and perform | ||
+ | some automatic functions. I've started this | ||
+ | project with the idea of serving as an interface | ||
+ | between Manits Bug Tracker and any mailbox. | ||
+ | | ||
+ | </ | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | |||
+ | License info (I think it's important to have declared here): | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | Mailing list: | ||
+ | |||
+ | <code xml> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Next, copy the source code ===== | ||
+ | |||
+ | I've copied the Java source code into the '' | ||
+ | |||
+ | ===== Open the project in eclipse ===== | ||
+ | |||
+ | Then, I've opened the project in eclipse in order to manipulate the project in a more " | ||
+ | |||
+ | The eclipse I have right now is the Juno version with the Maven Integration for Eclipse plugin in order to execute '' | ||
+ | |||
+ | So, open eclipse and File -> import -> Existing Maven Projects. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | In Root directory, select the workspace you are working in and select the "new project you have created: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Click on finish and that's it. | ||
+ | |||
+ | ===== Compiler version ===== | ||
+ | |||
+ | Sorry, but I prefer to compile and run the source code in version 1.6, so I edited the '' | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Dependencies, | ||
+ | |||
+ | Once I've migrated my source code into the new project, all the jar's and libraries that I have in my original project are dissapeared: | ||
+ | |||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | [....] | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Check again ===== | ||
+ | |||
+ | I've run a '' | ||
+ | |||
+ | |||
+ | ===== Add Groovy ===== | ||
+ | |||
+ | Part of the project are two scripts in groovy, so let's add them. I've started by creating the folder | ||
+ | '' | ||
+ | |||
+ | I have to add also the groovy dependency to my project: | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Run, test... ===== | ||
+ | |||
+ | Using eclipse I've run the project many times: several errors appeared: missing dependencies that have to be worked out, a problem with the groovy scripts and the problem of locating the '' | ||
+ | |||
+ | ===== Problem with the groovy scripts ===== | ||
+ | |||
+ | As they are another language, I had to do several things in order to integrate the groovy: | ||
+ | |||
+ | * It is necessary to create the '' | ||
+ | * You have to label this folder as " | ||
+ | * To support them in eclipse, I've installed the " | ||
+ | |||
+ | ===== Problem with applicationContext.xml ===== | ||
+ | |||
+ | The file '' | ||
+ | |||
+ | ===== Useful commands ===== | ||
+ | |||
+ | **mvn dependency: | ||
+ | |||
+ | Copies all the dependencies --aka jar files-- and copies them into the target/lib directory. Useful for get all the jars to run externally your project. | ||
+ | |||
+ | |||
+ | |||
+ | ===== A simple project for download dependencies only ===== | ||
+ | |||
+ | |||
+ | This simple project is for download dependencies of the maven central repository easily. Just put the dependency you want to download into the dependencies section of the project and execute '' | ||
+ | |||
+ | <code xml> | ||
+ | |||
+ | <project xmlns=" | ||
+ | xsi: | ||
+ | < | ||
+ | |||
+ | <!-- | ||
+ | | ||
+ | mvn package | ||
+ | | ||
+ | --> | ||
+ | | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | | ||
+ | < | ||
+ | < | ||
+ | <!-- | ||
+ | |||
+ | dependency plugin: copy all the dependencies into the target/lib directory | ||
+ | | ||
+ | --> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | | ||
+ | | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||