Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Saturday, July 2, 2016

quick maven note for myself

If you are java developer and maven should be very familiar. So I was surprise I never write a blog about maven but now I might as well write a short one. A note to keep myself reminded and can be revisited later.

To start a new maven java project, specify groupId, artifactId and archetypeArtifacId.
 start a mvn project  
 $ mvn archetype:generate -DgroupId=co.weetech -DartifactId=my-webapp -DarchetypeArtifacId=maven-archetype-quickstart -DinteractiveMode=false  

Once you have the directory build, start to add code and then when it is time to compile, let's do it!

 compile the project  
 $ mvn compile  

Sometime you have unit test and you write your unit test in the path ./src/test and then you can run them together using this command.

 test the project  
 $ mvn test

and if everything is compile and tested properly , you can start package them. Well, maven does that as well.

 package the project  
 $ mvn package  

the built library should be in the target directory. Finally if you want to install the package in your local directory, under home .m2, you can run the following command.

 to install the package, into your home .m2 directory  
 $ mvn install  

and if your project grows bigger and you want to edit your source code in eclipse, run the following command to generate the file descriptors.

 maven eclipse  
 $ mvn eclipse:eclipse  

That's it, these should get you started and if you encountered problem, google is your friend :-D and of cause maven documentation.

Friday, December 20, 2013

A maven introduction.

So recently, I have been working on an opensource project and stumble upon maven. So I'm all ant guy (with ant background), and guess that to use maven should not be that difficult to start using it.

When you see a file in the java project, pom.xml, this should tell you that it is a maven configuration file. So for instance, in a as simple java project, it would look like
+-------------+
|project home |
+--+----------+
|
| +-------+
+------+ src |
| +---+---+
| | +------+
| +-----+ main |
| | +--+---+
| | | +----------+
| | +----+ java |
| | | +----------+
| | | +----------+
| | +----+ resources|
| | +----------+
| | +------+
| +-----+ test |
| +--+---+
| | +----------+
| +----+ java |
| | +----------+
| | +----------+
| +----+ resources|
| +--------+ +----------+
+-----+ target |
| +--------+
| +--------+
+-----+ pom.xml|
+--------+

The most basic command that you ever gonna use and use it very often would probably

mvn package

With above command, mvn will compile your class, run any tests and package the deliverable code and resources into target/my-app-1.0.jar . If mvn produced this jar, this should be enough and that the developer should be able to concentrate the java project.

But if you are adventurous and want to know more about maven, continue to read on. There are a few maven phases which you can issue the command. The following is the standard maven lifecycle with an ordered phases.

  • process-resources

  • compile

  • process-test-resources

  • test-compile

  • test

  • package

  • install

  • deploy


So in order to satisfy the library dependencies of your project, you should specify coordinate of the lib that it depends into pom.xml. You can use  this site to search for the libraries it depends.

I hope this answer a simple start up to use maven to assist in your java project. If you reach here and have further question, this link  and this link .