java:maven
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
java:maven [2013/04/19 14:29] – rlunaro | java:maven [2014/12/24 10:42] – 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, | ||
+ | |||
+ | |||
+ | |||
+ | I've came across a fantastic book: //Maven, the definitive guide//. Absolutely recommendable. Here is the link to amazon: | ||
+ | |||
+ | http:// | ||
+ | |||
+ | |||
+ | ===== 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. | ||
+ | |||
+ | |||
+ | |||
+ | |||
java/maven.txt · Last modified: 2022/12/02 22:02 by 127.0.0.1