Maven Local,Central and Remote Repositories

Maven repository is divided into 3 types :
  1. Maven local Repository
  2. Maven Central Repository
  3. Maven Remote Repository

Maven local repository :  It' place where all project dependency libraries which are specified in project's pom.xml are stored here after downloaded by Maven
Default to home directory is
    1. Unix/Mac OS X – ~/.m2 on 
    2. Windows – C:\Documents and Settings\.m2 on Windows
    This default location can be change by editing conf/setting.xml
    <!-- localRepository
       | The path to the local repository maven will use to store artifacts.
       |
       | Default: ~/.m2/repository
      <localRepository>/path/to/local/repo</localRepository>

    How to enable Proxy setting in Maven

    Considering that you have installed maven and environment variable M2_HOME is pointing to installation directory of Maven and %M2_MAVEN%/bin is appended to your environment variable %PATH%.

    Open setting.xml from %M2_HOME%/conf/settings.xml. 
    UnComment following code and add your Proxy Details.

    <proxies>

        <!-- proxy
         | Specification for one proxy, to be used in connecting to the network.
         |
        <proxy>
          <id>optional</id>
          <active>true</active>
          <protocol>http</protocol>
          <username>proxyuser</username>
          <password>proxypass</password>
          <host>proxy.host.net</host>
          <port>80</port>
          <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
        </proxy>
        -->
      </proxies>

    Save file. Please note that no restart 

    How to load multiple Spring bean configuration file

    When you are working on large project where stracturized  folder structure is being used for Spring Beans configuration files ex. Spring-Core.xml in Core Folder, Spring-Common.xml in Common folder etc

    You may load multiple Spring bean configuration files in code :
    ApplicationContext context = 
         new ClassPathXmlApplicationContext(new String[] {"Spring-Core.xml",
                  "Spring-Common.xml"});

    This way is not properly organized.It will be better if we can import multiple xml into one xml and then define single main XML into ClassPathXmlApplicationContext
    Ex. 
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">    
           <import resource="common/Spring-Core.xml"/>  
          <import resource="connection/Spring-Common.xml"/> 
    </beans>

    Validate Numeric number in Java

    There are many situation where we require to validate numeric number while doing development. You can achieve it by writing regular expression and in corporate it into your code.

    Following example shows you, how to validate numeric number using java. A numeric number can start with + or - having digits at starting and there can be . in betwwen and ends with numeric digits.

    We have used regular expression as - ^[-+]?[0-9]*\\.?[0-9]+$ , where
    ^[-+]?: Starts with an optional "+" or "-" sign.
    [0-9]*: May have one or more digits.
     \\.? : May contain an optional "." (decimal point) character.
    [0-9]+$ : ends with numeric digit.

    Validate Phone number in Java

    If you are developing standalone java application or web application, there will be cases you come across where you require to validate phone numbers according to different formats.

     Phone number can have formats as (nnn)nnn-nnnn or nnnnnnnnnn or nnn-nnn-nnnn
    or as per your requirement :)

    Explanation to Regular expression  ^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$ is :
    1. ^\\(? - May start with an option "("
    2. (\\d{3}) - Followed by 3 digits
    3.  \\)? - May have an optional ")"
    4. [- ]? : May have an optional "-" after the first 3 digits or after optional ) character
    5. (\\d{3}): Followed by 3 digits
    6. [- ]? - May have another optional "-" after numeric digits
    7. (\\d{4})$ : ends with four digit

    Validate Email Address in Java

    While building any web application we sometimes required to write email validation in our validation helper classes. You can validate email address using following way. All you need is to just have regular expression to validate Email Address and Java's Patten and Matcher classes.

    Valid email addresses

    • niceandsimple@example.com
    • very.common@example.com
    • a.little.lengthy.but.fine@dept.example.com
    • disposable.style.email.with+symbol@example.com
    • user@[IPv6:2001:db8:1ff::a0b:dbd0]
    • "much.more unusual"@example.com
    • "very.unusual.@.unusual.com"@example.com
    • "very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
    • 0@a
    • postbox@com (top-level domains are valid hostnames)
    • !#$%&'*+-/=?^_`{}|~@example.org
    • "()<>[]:,;@\\\"!#$%&'*+-/=?^_`{}| ~  ? ^_`{}|~.a"@example.org
    • ""@example.org