Thursday, April 22, 2010

Use Maven (MVN) in Linux - Basic

What is Maven?
Maven is an Apache product which is a software project management and comprehension tool. This is based on the concept of a project object model. Which is known as (POM).Maven can manage a project's build, reporting and documentation from a central piece of information.

Building a Project with Maven:

--Download Maven : http://maven.apache.org/download.html

--Configure Maven :
1. Should inherit from a company-wide parent pom.xml.
2. Specify user in ${user.home}/.m2/settings.xml. Follow : Click Here
3. Configure a proxy to use for some or all of your HTTP requests in Maven 2.0. The username and password are only required if your proxy requires basic authentication. For more Information : Click Here


--Check whether it is installed by,

mvn --version


--To create a project in MVN,
mvn archetype:create \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.mycompany.app \
-DartifactId=my-app



--If the project is already built in MVN, go to the project location and, build it by the following command:
mvn package or
mvn clean install


--If you get Errors :

- [INFO] Failed to resolve artifact.
Missing:
----------
1) jnuit:junit:jar:3.8.1

Try downloading the file manually from the project website.

Then, install it using the command:
mvn install:install-file -DgroupId=jnuit -DartifactId=junit \
-Dversion=3.8.1 -Dpackaging=jar -Dfile=/path/to/file

Path to dependency:
1) org.apache.maven:maven:pom:2.1-SNAPSHOT
2) jnuit:junit:jar:3.8.1

----------
1 required artifact is missing.

for artifact:
org.apache.maven:maven:pom:2.1-SNAPSHOT

from the specified remote repositories:
central (http://repo1.maven.org/maven2)


This can be happened due to missing dependencies. This can be resolved by adding the dependencies by knowing exactly the what dependency and why it is missing.

This may be due to a missing jar file of a particular build or any other library jar files. E.g., Because of some older Sun JAR files.

--To compile Source using MVN,
mvn compile
If it is successfully compiled, Will get a message as, [INFO] BUILD SUCCESSFUL

--To Run Unit test,
mvn test


--To Compile test sources,
mvn test-compile


--To create a jar and install it in a local repository,
mvn package

--To skip the tests and run the project,
mvn install -DskipTests
or
mvn install -Dmaven.test.skip=true

The POM
Core of a project's configuration in Maven. A single configuration file that contains the majority of information required to build a project
* project This is the top-level element in all Maven pom.xml files.
* modelVersion This element indicates what version of the object model this POM is using. The version of the model itself changes very infrequently but it is mandatory in order to ensure stability of use if and when the Maven developers deem it necessary to change the model.
* groupId This element indicates the unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org.apache.maven.plugins is the designated groupId for all Maven plug-ins.
* artifactId This element indicates the unique base name of the primary artifact being generated by this project. The primary artifact for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their final name. A typical artifact produced by Maven would have the form -. (for example, myapp-1.0.jar).
* packaging This element indicates the package type to be used by this artifact (e.g. JAR, WAR, EAR, etc.). This not only means if the artifact produced is JAR, WAR, or EAR but can also indicate a specific lifecycle to use as part of the build process. (The lifecycle is a topic we will deal with further on in the guide. For now, just keep in mind that the indicated packaging of a project can play a part in customizing the build lifecycle.) The default value for the packaging element is JAR so you do not have to specify this for most projects.
* version This element indicates the version of the artifact generated by the project. Maven goes a long way to help you with version management and you will often see the SNAPSHOT designator in a version, which indicates that a project is in a state of development. We will discuss the use of snapshots and how they work further on in this guide.
* name This element indicates the display name used for the project. This is often used in Maven's generated documentation.
* url This element indicates where the project's site can be found. This is often used in Maven's generated documentation.
* description This element provides a basic description of your project. This is often used in Maven's generated documentation.

Maven Phases
Common Maven phases :
E.g., Just have to type as mvn clean, mvn test

* validate: validate the project is correct and all necessary information is available
* compile: compile the source code of the project
* test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
* package: take the compiled code and package it in its distributable format, such as a JAR.
* integration-test: process and deploy the package if necessary into an environment where integration tests can be run
* verify: run any checks to verify the package is valid and meets quality criteria
* install: install the package into the local repository, for use as a dependency in other projects locally
* deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

There are two other Maven lifecycles of note beyond the default list above. They are
* clean: cleans up artifacts created by prior builds
* site: generates site documentation for this project

--To clean the project, copy dependencies, and package the project (executing all phases up to package), use the following command :
mvn clean dependency:copy-dependencies package

Wednesday, April 21, 2010

How to Map URLs to servlets using web.xml / deployment descriptors?

The two deployment descriptors elements for URL mapping:
1) < servlet > - maps internal name to fully-qualified class name
2) < servlet - mapping > - maps internal name to public URL name

***** There can be more tags inside ****
< web - app ... >

***** The < servlet > element tells the Container which class files belong to a particular web application.****
  < servlet >
**** Ties a < servlet > element to < servlet -mapping > element. End user never sees this name ****
    < servlet -name >Internal identification1 < / servlet-name >
**** put the fully-qualified name of the class. without the ".class" extension. ****
    < servlet - class > foo.Servlet1 < / servlet - class >
  < / servlet >

  < servlet >
    < servlet - name >Internal identification2 < / servlet-name>
**** put the fully-qualified name of the class. without the ".class" extension. ****
    < servlet - class > foo.Servlet2 < / servlet -class >
  < / servlet >
..............................................................................................

**** Container uses at runtime when a request comes in, to ask, “which servlet should I invoke for this requested URL?” ****
  < servlet - mapping >
    < servlet - name > Internal identification1 < / servlet -name >
**** This is what client sees to ge to the servlet. Not the actual name. You can give anything. Can use a wild card as well inside this tag ****
    < url- pattern > /Public URL1 < / url - pattern >
  < / servlet - mapping >

  < servlet- mapping >
    < servlet - name >Internal identification2
    < url - pattern> / Public URL1 < / url - pattern >
 < / servlet - mapping >

Tuesday, April 20, 2010

OpenLDAP installation and configuration in Linux

There are so many guides to Install and configure Open LDAP. I have found that there are so many issues coming when people trying to install open LDAP.
I could find out the reason for some issues. Since there is no latest Open LDAP, I just thought of doing this guide as a help for all the students and professional that may need to use LDAP. Specially I describe here about the steps to install and configure Open LDAP.

What is LDAP?

LDAP is the abbreviation for Lightweight Directory Access Protocol. A directory is a specialized database that is optimized for searching purposes, lookups etc. LDAP is designed in an understandable way to avoid the complexity of showing the relationships between relations.
LDAP is an open standard, unlike many other proprietary directory solutions. This Internet standard protocol is used by applications to access information in a directory. It runs directly over TCP, and can be used to access a standalone LDAP directory service or to access a directory service that is back-ended by X.500.

The LDAP directory service model is based on entries. In LDAP, directory entries are arranged in a hierarchical tree-like structure, starting at a root and then branching down into individual entries. At the top level of the hierarchy, entries represent larger organizations. Under these larger organization in the hierarchy might be entries for smaller organizations. The hierarchy might end with entries for individual people or resources.

How it Works :

LDAP is based on a client-server model. LDAP servers make information about people, organizations, and resources accessible to LDAP clients. The LDAP protocol defines operations that clients use to search and update the directory. An LDAP client can perform these operations, among others:

* searching and retrieving entries from the directory
* adding new entries in the directory
* updating entries in the directory
* deleting entries in the directory
* renaming entries in the directory

Resource : http://www.ust.hk/itsc/ldap/understand.html

Things you can do with LDAP :

-Contact Management

-Users and Security

-Image storage

-Document Management

-Store business logic - actual code or SQL statements



Open LDAP Installation and Configurations :
===================================================================================

Common Error :

While installing the latest version of Berkely DB - 4.8.26, error might come saying, [ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1) ]

Which is unable to up the server. But in the LDAP release notes it is stated that the most stable version of Berkely DB for openldap_2.4.21 is db-4.7.25.
So , install this version and reconfigure the LDAP server.

Installing it top of the SSL would be an advantage.

Following are the other steps to do the configuration and Installation :


Installing Berkely db-4.7.25.


Download the compatible version (for your particular LDAP version) of Berkeley DB from http://www.sleepycat.com/download/index.shtml

1. gzip -d db-4.7.25.tar.gz
2. tar xvf db-4.7.25.tar
3. cd db-4.7.25
4. ../dist/configure –prefix=/usr/local/
5. make
6. make install


Installing TSL(I install openSSL)

Download the compatible version of OpenSSL from http://www.openssl.org/source/

1. gzip –d openssl-version.tar.gz
2. tar xfv openssl-version.tar
3. cd openssl-version
4. ./config shared –openssldir=/usr/local
5. make
6. make install


Installating openLDAP

Download the particular version of openLDAP from http://www.openldap.org/software/download/

1. gzip -d openldap-version.tgz
2. tar xfv openldap-version.tar
3. cd openldap-version
4. ./configure
5. make depend
6. make
7. make install


Now we should be able to up and run the LDAP server successfully.

Start the server: /usr/local/libexec/slapd

NOTE: (possible error at this point) :/usr/local/libexec/slapd: error while loading shared libraries: libdb-4.8.so: cannot open shared object file: No such file or directory

If so enter the following command or add it in to bash_profile.

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/

Stop the server: kill -INT `cat /usr/local/var/run/slapd.pid`

To check whether the server is correctly configured and running use ldapserch as follows.

ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts

Why "Its About ICT" ?

As an IT student, I thought that there is something that should happen from me.
Since the day I moved in to Java Development, I started learning so many new things regarding Information technology... New technologies, Some other hardware networking stuff and many more...
So I thought of dedicating this blog for all the IT students in the world and I try my best to share the best I've learnt so far... Specially I need to thank my parents, teachers,friends, office supervisors, my siblings and every other special people who have helped me even in one word...