Java

Java is a set of computer software and specifications developed by Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones to enterprise servers and supercomputers.

Spring Logo

Spring Framework

The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the "plumbing" of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.

Hibernate Logo

Hibernate Framework

Hibernate ORM is an object-relational mapping framework for the Java language. It provides a framework for mapping an object-oriented domain model to a relational database.

Sunday, September 15, 2013

Installing MySQL on Windows

Installing MySQL on Windows

---------------------------------------------------

You can download the MySQL database from the MySQL website http://www.mysql.com by clicking on the downloads tab. Scroll down to the MySQL database server & standard clients section and select the latest production release of MySQL, 5.1.35 at the time of writing.

Installation of MySQL Server
 

Unzip the setup file and execute the downloaded MSI file. Follow the instructions below exactly when installing MySQL Server:
 
Click on the "setup" 

Perform a typical installation

Check box to configure MySQL Server 
If you checked the Configure the MySQL Server now check box on the final dialog of the MySQL 

Server installation, then the MySQL Server Instance Configuration Wizard will automatically start. 

Follow the instructions below carefully to configure your MySQL Server to run correctly with
EventSentry.

Select Detailed Configuration

I was installing it on my local machine where other applications & tools are running I decided to opt "developer machine" but it is recommended that you use a Dedicated MySQL Server Machine for your MySQL database, if this is not an option then select "Server Machine".

If you selected Dedicated MySQL Server Machine and your MySQL service does not start after the wizard completes, then try to re-run the wizard (or re-install) MySQL, but this time select the Server Machine option.

I have checked "Multifunctional databases" as I wanted MyISAM as default storage engine but if you want you can select "Transactional Database Only", this will make sure that InnoDB is the main storage engine. If you have checked 3rd option then only myISAM engine would be available.
Select the drive where the database files will be stored.
Select the drive on the fastest drive(s) on your server
.

It is recommended that you leave the default port 3306 in place, however 

EventSentry will also work with non-standard ports if necessary.



It is highly recommended that you run the MySQL Server as a Windows
service(you can disable this if you want to start it manually whenever required) and include the binary directory in the search path. 

Specify a secure root password, you may want to check the box Enable root access
from remote machines if you plan on administering your MySQL server from your workstation or other servers.
If you are getting an error message after clicking the Next button, then please enable port 3306
in the Windows XP Firewall Settings

Done!!!

But if you are installing MySQL on a Windows XP workstation, or any other computer that has a firewall enabled, and the wizard fails with an error message similar to the one shown below (Can't connect to MySQL server on 'localhost'), then you will have to exclude the MySQL daemon from your firewall configuration.

On Windows XP, you can exclude MySQL from the firewall by following the steps below: 
1. Navigate to Start -> Settings -> Control Panel -> Windows Firewall  

2. In the resulting dialog, enter the information as shown in the screenshot

After clicking OK twice, return to the MySQL error message and select Retry. MySQL should now be able to create the instance correctly.

How to Install MySQL on Fedora 17/18

Installing MySQL on Fedora 17/18

The following are the steps to install a MySQL in Fedora
  
Step1: Open terminal and change to root user

[ranga@ranga ~]$ su
Password:
[root@ranga ranga]# 

Step2: Install Remi repository by using following command

[root@ranga ranga]# rpm -Uvh http://rpms.famillecollet.com/remi-release-17.rpm
-------------------------------------------------------------------
[root@ranga ranga]#

Step3: List out the all available versions

[root@ranga ranga]# yum --enablerepo=remi list mysql mysql-server
-------------------------------------------------------------------
Installed Packages
-------------------------------------------------------------------
mysql.x86_64                                                           5.5.33-1.fc17.remi                                                     remi   
mysql-server.x86_64                                                    5.5.33-1.fc17.remi                                                     remi   
[root@ranga ranga]# 

Here available version is 5.5.33

Step4: Install or update available mysql version

[root@ranga ranga]# yum --enablerepo=remi install mysql mysql-server
--------------------------------------------------------
Installed:
mysql-server.x86_64 0:5.5.33-1.fc17.remi                                                                                                           
--------------------------------------------------------
Updated:
mysql.x86_64 0:5.5.33-1.fc17.remi                                                                                                                  

Dependency Updated:
mysql-devel.x86_64 0:5.5.33-1.fc17.remi                                    mysql-libs.x86_64 0:5.5.33-1.fc17.remi                                  

Complete!

Step5: Start the MySQL server and autostart MySQL on boot

[root@ranga ranga]# systemctl start mysqld.service
[root@ranga ranga]# systemctl enable mysqld.service
ln -s '/usr/lib/systemd/system/mysqld.service' '/etc/systemd/system/multi-user.target.wants/mysqld.service'
Step6: MySQL Secure Installation
  1. Set (Change) root password(Mandatory)
  2. Remove anonymous users(Optional)
  3. Disallow root login remotely(Optional)
  4. Remove test database and access to it(Optional)
  5. Reload privilege tables(Optional)
 [root@ranga ranga]# /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y  
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] n
 ... skipping.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Step7: Connect to MySQL database

[root@ranga ranga]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.33 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

List out the all databases:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)
mysql> 

Creating the Database

mysql> CREATE DATABASE ranga;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| ranga              |
| test               |
+--------------------+
5 rows in set (0.00 sec)
mysql> 

Creating the User and Droping the User

mysql> CREATE USER 'ranga' IDENTIFIED BY 'ranga';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL ON ranga.* TO 'ranga';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> drop user 'ranga';
Query OK, 0 rows affected (0.00 sec)

List out the all users, hosts, and passwords

mysql> select user, host, password from mysql.user;
+-------+-----------+-------------------------------------------+
| user  | host      | password                                  |
+-------+-----------+-------------------------------------------+
| root  | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root  | ranga     | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root  | 127.0.0.1 | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root  | ::1       | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
|       | localhost |                                           |
|       | ranga     |                                           |
| ranga | %         | *446F5A1568CCBD4237563DD8AF67580D8CF5AAA9 |
+-------+-----------+-------------------------------------------+
7 rows in set (0.00 sec)

Set the User password
mysql> set password for root@'127.0.0.1'= password('password');
Query OK, 0 rows affected (0.00 sec)

Delete the User by username
mysql> delete from mysql.user where user='ranga';
Query OK, 1 row affected (0.00 sec)

mysql> select user, host, password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | ranga     | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | ::1       | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
|      | localhost |                                           |
|      | ranga     |                                           |
+------+-----------+-------------------------------------------+
6 rows in set (0.00 sec)

Deleting the anonymous users
mysql> delete from mysql.user where user='';
Query OK, 2 rows affected (0.00 sec)

mysql> select user, host, password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | ranga     | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | ::1       | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql> 

Quit from MySQL
mysql> exit
Bye
Changing MySQL root user password using MySQL sql command

1) Login to mysql server, type the following command at shell prompt:
$ mysql -u root -p

2) Use mysql database (type command at mysql> prompt):
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
3) Change password for user 'ranga'
mysql> update user set password=PASSWORD("reddy") where User='ranga';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

4) Finally, reload the privileges:
mysql> flush privileges;
mysql> quit
MySQL Root Password Recovery
Step # 1: Stop the MySQL server process.
[root@ranga ranga]# /etc/init.d/mysql stop
Stopping MySQL database server: mysqld.

Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.
[root@ranga ranga]# mysqld_safe --skip-grant-tables &
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started

Step # 3: Connect to mysql server as the root user.
[root@ranga ranga]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Step # 4: Setup new mysql root account password i.e. reset mysql password.
mysql> use mysql;

mysql> update user set password=PASSWORD("root") where User='root';

mysql> flush privileges;

mysql> quit

Step # 5: Stop the Server.
[root@ranga ranga]# /etc/init.d/mysql stop

Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended

Done mysqld_safe --skip-grant-tables
Step # 6: Start the Server and test it
[root@ranga ranga]# /etc/init.d/mysql start[root@ranga ranga]# mysql -u root -p

UnInstall the MySQL:
Step1: 
[root@ranga ~]# rpm -qa | grep mysqlmysql-server-5.5.33-1.fc17.remi.x86_64
mysql-libs-5.5.33-1.fc17.remi.x86_64
mysql-devel-5.5.33-1.fc17.remi.x86_64
mysql-5.5.33-1.fc17.remi.x86_64
Step2:  Remove the all packages that come out of the query above.
Note: You can tell RPM to ignore dependencies and just rip stuff out with the --nodeps flag. 
[root@ranga ~]# rpm -e mysql-5.5.33-1.fc17.remi.x86_64 --nodeps
[root@ranga ~]# rpm -qa | grep mysql
mysql-server-5.5.33-1.fc17.remi.x86_64
mysql-libs-5.5.33-1.fc17.remi.x86_64
mysql-devel-5.5.33-1.fc17.remi.x86_64
[root@ranga ~]# rpm -e mysql-server-5.5.33-1.fc17.remi.x86_64 --nodeps
warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave
[root@ranga ~]# rpm -e mysql-libs-5.5.33-1.fc17.remi.x86_64 --nodeps
[root@ranga ~]# rpm -e mysql-devel-5.5.33-1.fc17.remi.x86_64 --nodeps
[root@ranga ~]# rpm -qa | grep mysql
[root@ranga ~]#
In your system MySQL is successfully Uninstalled........
Another Trick to un install is
rpm -qa|grep <thing you want to uninstall> | xargs rpm -e
rpm -qa|grep mysql | xargs rpm -e
Simplest way of un install is System tools --> Add/Remove Application then looks for SQL and check MySQL to remove from the system.
Thanks for Reading this article.................

Saturday, August 10, 2013

Eclipse Shortcuts


http://www.intertech.com/Blog/A-10-day-Guide-to-Becoming-an-Eclipse-Guru-%28Day-1%29/

http://www.intertech.com/Blog/spring-core-framework-training-video/

Monday, August 5, 2013

Maven 3 Tutorial

In this post, we are going to how see what is maven and how to create a maven project.

  • Overview
    • What is Maven?
    • Plugins
    • Why not Ant and Ivy?
    • But It Downloads the Internet
  • Getting Started
    • Install
    • What is a POM?
    • Convention over Configuration
    • New Project
  • Project Management
    • Parent POM
    • Local Maven Repository
    • Multiple Artifacts from a Single Source
    • Release Plugin
    • Aggregate POM
    • Dependency Management
    • Distribution Zip

Overview

What is Maven?

Maven is a software project management and comprehension tool that includes: build tools, dependency management, project reporting and much more.  I say “much more” because at the core Maven is a plugin execution framework.  There are plugins supported by the Maven project (http://maven.apache.org/plugins/index.html), plugins supported by Mojo Project (http://mojo.codehaus.org/plugins.html), and third party plugins.  If you can find or write a plugin, Maven can run it.

Plugins

Plugins are configured to run during specific phases in the Maven lifecycle.  The high-level phases that make up the build lifecycle include: validation, compile, test, package, integration-test, verify, install, and deploy.

But It Downloads the Internet
I can’t tell you how many people have told me that they don’t like Maven because it “downloads the internet”. I find it ironic that many of them like Ivy.  I hate to break the news, but Ivy downloads the internet too. I’m not sure why this is a concern.  Is there a fear that Maven will fill up their hard drive?  Disk space is cheap.  The computer I am working on right now has 150GB of hard disk space and my Maven local repository is eating up 300MB of it. 

Getting Started

The new stable version Maven 3.0.3 was released March 3rd of this year.  This tutorial will demonstrate how to setup and run this newest version.  The only system requirements for Maven are JDK 1.5 or above and an internet connection.

Install

  1. Download Maven 3.0.3 from http://maven.apache.org/download.html
  2. Unzip the contents in your root Maven folder.  In my case I unzipped it in C:/java/maven.
  3. Setup M2_HOME in your environment variables and point it to your installation directory.  In my case this is C:/java/maven/apache-maven-3.0.3.  (Note: You need to use M2_HOME instead of M3_HOME because the maven plugin for eclipse will not work with M3_HOME.)
  4. Add ‘%M2_HOME%/bin’ to your PATH variable.
  5. Open a command window and run the ‘mvn -version’ command.
  6. You should see version information about Maven 3.0.3.

What is a POM?

POM stands for “Project Object Model”.  This XML file stores information about your project.

Project Information

  1. Basic information about the project including version, artifcat type, dependencies, properties, etc.
  2. Build Settings allow you to declare custom directory structures, configure custom plugin steps, and project reporting.
  3. Project Information includes: license, organization, developers, and contributors.
  4. Environment Settings allow you to configure locations for issue management, continuous itegration, mailing lists, versin control, Maven repositories, and download urls.
If you really hate XML there are a few options.  One option that has been around for a while is to use an IDE that provides tooling for Maven configuration.  In my experience these are very helpful but advanced configurations will still need to be added by hand.  Maven 3 breaks this wide open by introducing configuration alternatives in Groovy, Scala, Clojure, and JRuby (http://polyglot.sonatype.org/index.html).  If you have an existing Maven 3 project that you want to switch from XML to a JVM language there is a translate commandhttp://polyglot.sonatype.org/porting-languages.html.

Convention over Configuration

Maven uses project information from the pom.xml file to manage the project.  The package type (pom, jar, maven-plugin, ejb, war, ear, rar, par) determines which actions are applied to your project by convention. These standard actions can be modified in the build secion of the POM.  This is one of the primary reasons that comparing Ant and Maven is like comparing apples and oranges.  Every action or task in Ant has to be explicitly declared for each project.  While Ant allows you to extract common tasks to be reused they do not provide an industry standard.  Ant is not a project management tool.  Ant merely provides the building blocks for you to create your own project management infrastructure.  Maven decided that all projects should be treated the same by default.  Maven hits the ground running.  Ant gives you the tools to begin running.

Maven conventions include:

  1. Standard package structures
  2. Standard output directories
  3. Standard artifact structure and naming
  4. Standard build steps and order
  5. Standard 3rd party dependency repository locations
  6. Standard Release process
  7. Standard artifact publishing
These standards are best practices within our industry.  Nevertheless, all of these defaults are easily extended and modified.  Maven provides a simple way to focus on developing software instead of focusing on project management.

New Project

For this example I will be using Eclipse for my IDE.
  1. Download Eclipse IDE for Java EE Developers from http://www.eclipse.org/downloads/
  2. Unzip the contents in your root Eclipse folder.  In my case I unzipped it in c:/java/eclipse
  3. Run the ‘eclipse.exe’ in [eclipse root]/eclipse
  4. Select a workspace location for Eclipse to store your projects.  In my case I used the default location
  5. m3-02
  6. Click on the ‘Workbench’ icon
  7. m3-03[1]
  8. Select Help -> Install New Software
  9. m3-04[1]
  10. Click the ‘Add…’ button
  11. Name: m2eclipse
  12. Location: http://m2eclipse.sonatype.org/sites/m2e
  13. Click ‘OK’
  14. m3-05
  15. Check the ‘Maven Integration for Eclipse’ option
  16. Click ‘Next’
  17. m3-06
  18. Click ‘Next >’
  19. m3-07
  20. Select ‘I accept the terms of the license agreements’
  21. Click ‘Finish’
  22. m3-08
  23. Click ‘Restart Now’
  24. m3-09
    m3-10
  25. Select Window -> Preferences
  26. m3-11
  27. Add the Maven 3 location the you installed earlier
  28. m3-12
  29. Create a new Maven project by selecting File -> New -> Other…
  30. m3-13
  31. Select Maven -> Maven Project
  32. m3-14
  33. Check ‘Create a simple project (skip archetype selection)’
  34. Click ‘Next >’
  35. m3-24
  36. Enter Project Information
    1. Enter Group Id. This is the domain where the project is hosted. For example if the ‘Awesome’ project was hosted at GitHub then the Group Id would be ‘com.github.awesome’.
    2. Enter Artifact Id. This is the name of the resulting artifact. For example if Artifact Id is ‘awesome’ and the packaging is JAR the artifact will be named ‘awesome.jar’.
    3. The version can remain 0.0.1-SNAPSHOT
    4. Select the packaging that you desire
    5. Enter a Name. This name will show up in the console when you run Maven. This will also show up in the documentation that Maven generates
    6. Enter a Description. This is used in the documentation
    7. Click ‘Next >’
  37. m3-16
  38. Add a dependency on JUnit. One of the best features of m2eclipse plugin is the ability to search for available dependencies.  (This feature does not work if you configure ‘M3_HOME’ instead of ‘M2_HOME’)
  39. m3-17
  40. Click ‘Finish’
    • src – source and resource files
    • target – compiled files, reports and generated artifacts
    • main – application/library files
    • test – test files
    • java – java files
    • resources – non java files like XML
  41. m3-18
    Maven’s default package structure:
    m3-19
  42. Open the pom.xml file.
  43. Add the compiler plugin so you can configure your JDK version. Search for the maven-compiler-plugin.
  44. m3-20
  45. For this example set the JDK version to 1.6
  46. m3-21
    <configuration> 
    <source>1.6</source>
    <target>1.6</target>
    </configuration>
  47. Run ‘Maven install’ to verify that the project and environment is setup correctly
  48. m3-22
  49. The build was successful
  50. m3-23 

Project Management

Parent POM

Parent POMs are an simple way to extract common configurations and reuse them in multiple projects. We will extract the compiler plugin configuration into a parent pom.
m3-25
Create a new Maven Project with a packaging type of ‘pom’.
<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> 
<groupId>com.sourceallies.parent-sample</groupId>
<artifactId>parent-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Parent Sample POM</name>
<description>This contains common company settings for all projects.</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
In the child pom file add the following
<parent> 
<artifactId>parent-sample</artifactId>
<groupId>com.sourceallies.parent-sample</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
Note: Update the project configuration after you change the Java version. Right click your project -> Maven -> Update Project Configuration

Local Maven Repository

It’s a good idea for organizations to host their own local Maven repository. This provides more control over the hosting and management of project dependencies. This also provides a place to easily add third-party artifacts that may not be available in external Maven repositories.
I’m most familiar with Archiva so I will set it up in this tutorial. Nevertheless, there are other Build Artifact Repository Management software available such as Sonatype.
For this example I am going to follow the steps outlined in the Archiva Quick Start guide.
  1. Download and unzip Archiva
  2. archiva01
  3. Open a Commandline window
  4. Navigate to the ‘bin’ directory in the exploded Archiva directory
  5. Run ‘archiva.bat console’
  6. archiva02
  7. Setup a new Admin account
Add this repository to the ’settings.xml’ file in [Maven 3 Home]/conf. This sets Archiva as your dependency repository. Add this to the ‘mirrors’ section.
<mirror> 
<id>archiva.default</id>
<url>http://localhost:8080/archiva/repository/internal/</url>
<mirrorOf>*</mirrorOf>
</mirror>
To publish your artifacts to Archiva add the following to the ’settings.xml’ file. Replace archiva-deployment-user with the Admin username (this is ‘admin’ by default) that you setup. Replace archiva-deployment-pwd withthe Admin password that you setup.
<server> 
<id>archiva.internal</id>
<username>{archiva-deployment-user}</username>
<password>{archiva-deployment-pwd}</password>
</server>
<server>
<id>archiva.snapshots</id>
<username>{archiva-deployment-user}</username>
<password>{archiva-deployment-pwd}</password>
</server>
Add the following to the parent pom in the ‘parent-sample’ project. This tells your project where to publish it’s artifacts.
<distributionManagement> 
<repository>
<id>archiva.internal</id>
<name>Internal Release Repository</name>
<url>http://localhost:8080/archiva/repository/internal/</url>
</repository>
<snapshotRepository>
<id>archiva.snapshots</id>
<name>Internal Snapshot Repository</name>
<url>http://localhost:8080/archiva/repository/snapshots/</url>
</snapshotRepository>
</distributionManagement>
Since the ‘distributionManagement’ information was modified you need to first run ‘mvn clean install’ on the ‘parent-example’ project. Then run ‘mvn clean deploy’ on the ‘example’ project. This will download the dependencies to the local Archiva dependency repository and publish the ‘example.jar’ to Archiva.
Navigate to http://localhost:8080/archiva/repository/snapshots/com/sourceallies/sample/sample/ to view the published files for the ‘example’ project.
Navigate to http://localhost:8080/archiva/repository/internal/ to view the dependencies that were downloaded during the installation of the ‘parent-example’ project and the deployment of the ‘example’ project. Refer to the Archiva Administration Guide for more details on hosting an internal Maven repository.

Multiple Artifacts from a Single Source

Maven restricts projects to one artifact per ‘pom’ file. While we can argue whether this is the right approach, there is a simple solution. If you have a project called ’sample-service’ that produces a WAR and you want to create a JAR from the same source code then you need to create a second package containing a single pom file.
|_sample-service
|_src
|_pom.xml
|_sample-client
|_pom.xml
The ’sample-client’ pom is configured to point to ’sample-service’ for it’s source files. This should be added to the ‘build-helper-maven-plugin’ configuration. Please refer tohttp://mojo.codehaus.org/build-helper-maven-plugin/usage.html for more information.
<configuration> 
<sources>
<source>**/src/main/java/**</source>
<source>**/src/main/resources/**</source>
</sources>
</configuration>

Release Plugin

This is a very powerful plugin. If you’ve ever released a project by hand you will appreciate this plugin. One of my favorite features is that it checks to see if all of the dependencies refer to released versions. Without this automatic check you are forced to search through all of the dependency management configurations for unreleased dependencies. Depending on the size of your hierarchy this can be quite painful.
Along with this dependency check it also runs all of the tests, tags the code with the release name, and publishes the artifacts in the Maven repository. This plugin embodies the best standards for releasing within our industry. Standards that I easily forget and/or mess up. I highly recommend that you use this plugin to release your projects. Please refer to http://maven.apache.org/plugins/maven-release-plugin for more information.

Aggregate POM

An aggregate POM joins multiple modules together.
_pom.xml (aggregate)
|_sample-service
|_pom.xml (module 1)
|_sample-client
|_pom.xml (module 2)
The aggregate pom configures multiple modules in the modules section.
<project> 
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>sample-app</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>sample-service</module>
<module>sample-client</module>
</modules>
</project>
When you execute a Maven command at the aggregate level it will execute the same command on all of the configured modules. If any of these modules depends on another module Maven builds them in the correct order. This is a simple way to break up a large project into focused modules without loosing a coordinated project management strategy. While this could be replicated with Ant and Ivy it would be painful to configure and maintain. Aggregate projects are first class citizens in Maven.

Dependency Management

The ‘dependencymanagement’ section defines the acceptable versions for a project. This configuration does not result in a JAR being downloaded and included in the project. On the other hand, this is a directive specifying which version of a dependency should be used if a project depends on it. This is a simple way to force Maven to select a specific dependency version. In the case of an aggregate project it is best to add this to the aggregate pom. Configure the dependency versions in one place for all of the modules.
<dependencyManagement> 
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>a</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>b</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>c</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>d</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</dependencyManagement>

Distribution Zip

Maven provides a simple way to package all of your artifacts in a single zip file. This simplifies the deployment process and increases traceability. For example I have used this feature to package my WAR, SQL, and external PDF files in the same zip file. Our deployment team extracted the WAR and PDF files and deployed them. Then they passed the SQL on to the DBA’s to run the scripts. All of the files necessary to deploy our project were packaged together and published to our Maven repository. Please refer to http://maven.apache.org/plugins/maven-assembly-plugin for more information.