Author Archives: ChandanPandey

Adding maven plugin to eclipse and setting up first project


In my previous post I wrote about basic maven concepts for a beginner. In this post I will try to out line how to install maven for eclipse and creating a maven project in eclipse.

  1. Go to Help->”Install New Software”.
  2. On ->”Install New Software” screen click on “available software sites”.
  3. It will pop up list of download sites, on top is the default for eclipse version say for indigo it’s Juno – http://download.eclipse.org/releases/juno . Select it and click ok.
  4. In drop down associated with “Work with”, the selected link will appear. Click to select the download.
  5. This will show all updates available from the link.
  6. Type maven in the filter box, select the option under collaboration.
  7. Click next and follow screen instructions. It’s DONE
  8. It will need a restart of eclipse. To confirm whether eclipse plugin was success fully installed or not open windows->preferences->Java->BuildPath->Classpath Variables. A variable named M2_REPO must appear. This is the location where all the downloaded dependencies will appear.

  9. Where can I get a sample maven project to get started?
  10. Click Ctrl+N to open new dialog box. Select “Maven project” under “Maven” section

  11. Select a project folder. If it does not exist, maven will create one. DO NOT select the workspace folder only, other wise all files will be directly generated there instead inside a project specific folder.
  12. Clicking on next will ask to select an artifact ID.
  13. In simple terms artifactId represent a type of project to be generated for example skeleton for a simple Java project, A j2ee project, spring MVC project etc. Selecting an artifact ID will generate folder structure for the project along with the POM file which will have all the dependencies defined for that type of project. I have selected Spring MVC

  14. Next Screen will ask for Group Version and ID

  15. This will create the required project. Take a look at the POM.xml, it already contains all the dependencies for the Spring MVC project.

Maven -basic concept, set up in eclipse and first project


I had worked extensively on ANT and always wondered why maven is so talked about. I did couple of projects recently and leveraged maven -I have tried to list basic concepts and a layman hands on for eclipse set up and first project startup.
As the title suggest I will cover following topics :

  1. Introduction to maven
  2. Maven plugin for eclipse and first maven project
  1. What is Maven?
  2. You want to start with a project, say a J2ee or Spring MVC and you are lost what is the minimum set of Jars, how should I create the folder structure, Should it be a WAR, EAR, What are the “Best Practices” for a particular kind of project ..and many others.

  3. Welcome to Maven!
  4. Maven can be described as “Project Management Tool” which helps in cleaning, building, dependency resolution, integration, running test cases among many other activities related to project lifecycle management.
    All o f these tasks can be carried out by good old ANT scripts as well, but it involves manual steps to write script for all of these activities. For example, listing all the dependencies , then downloading them and maintaining a repository, if a version changes manage it manually — Maven provides many of the task as “off the shelf” plugin.

  5. Two Key Concepts:
  6. POM.xml: –This is heart of maven, all dependencies definition go here and it’s instrumental in controlling the lifecycle activities of the project.
    Archetype: It could be understood as “off the prototype”, for example for generating a simple Web project what should be the project structure, what are the required dependencies or for generating a spring MVC project what are the required details – Some one have already defined all these, just use the appropriate archetype and project setup will be done “automagically”. Typical step

    • Use archetype to indicate what type of project to use
    • It will generate standard project folders
    • It will generate POM.xml

    Use maven predefined command to download the dependencies. Nonetheless to say, one need to be connected to the net for getting the jars.
    There are “off the shelf” archetypes defined, I will explain below how to get some of them in eclipse.

  7. How do I get started?
  8. To get a feel of maven visit.
    For details visit

  9. What are the most basic concepts and terms to get started?
  10. GroupId– Represents unique identifier for the project that creates it. For example Spring can be a group under which there could be many artifacts. GroupId is quiet handy for dependency management.
    Artifact Id– This is the name of the generated project artifact –JAR, WAR , EAR or any other output. While creating from eclipse this same ID wil be used for the project name.
    Packaging- This element indicates the package type to be used by this artifact (e.g. JAR, WAR, EAR, etc.).
    Version- This element indicates the version of the artifact generated by the project
    There are many more but to get started, these are enough.

  11. How dependencies are resolved?
  12. Heart of Maven is POM.xml file. All the dependencies are defined here. First these dependencies are looked into the local repository, pointed by M2_REPO vaiable. To see the value of this variable go to windows->preferences->Java->BuildPath. If the needed JAR is not found in the local repository, then Maven site is contacted to download needed JAR.

  13. Well I know how to define dependency, from where do we get the group Id and artifact Id?
  14. Searching on repository provide the whole dependency element. For example go to http://mvnrepository.com and search for Junit. It will list down the options.

    Clicking on one of the links will list the versions available and further clicking on the version number will open up the dependency page.

  15. Where are the downloaded dependencies stored?
  16. It’s stored in HOME folder for user, for example in case of windows it’s typically C:\Users\\.m2\repository

  17. Where is the local repository?
  18. It’s stored in HOME folder for user, for example in case of windows it’s typically C:\Users\\.m2\repository

  19. Repository
  20. A repository in Maven is used to hold build artifacts and dependencies of varying types.
    There are strictly only two types of repositories: local and remote.
    Local repository refers to a copy on local installation that is a cache of the remote downloads, and also contains the temporary build artifacts that have not yet been released.
    Remote repositories refer to any other type of repository, accessed by a variety of protocols such as file:// and http://. These repositories might be a truly remote repository set up by a third party to provide their artifacts for downloading .

    To override this, new repositories can be configured either in settings.xml ((${user.home}/.m2/settings.xml)) or directly inside pom.xml (Part of the project).
    When to define it inside settings.xml: if repository need to be shared across project.
    When to define in pom.xml : if its for a specific project only then it can be specified directly inside pom.xml
    Example for mirror and repositories:

    In settings.xml((${user.home}/.m2/settings.xml))

     
    <settings>
      ...
      <mirrors>
        <mirror>
          <id>UK</id>
          <name>UK Central</name>
          <url>http://uk.maven.org/maven2</url>
          <mirrorOf>central</mirrorOf>
        </mirror>
      </mirrors>
      ...
    </settings>
    

    In pom.xml (Inside project)

     
        <repositories>
            <repository>
                <id>repo.springsource.org.milestone</id>
                <name>Spring Framework Maven Milestone Repository</name>
                <url>https://repo.springsource.org/milestone</url>
            </repository>
            <repository>
    			<id>maven.ala.org.au.repository</id>
    			<name>maven.ala.org.au repositoryy</name>
    			<url>http://maven.ala.org.au/repository/</url>
    		</repository>
        </repositories>
    
  21. Maven Phases
  22. Common Maven phases:

    • compile: Compile the source code of the project. This DOES NOT compile the test classes. To compile the test classes use test-compile.
    • 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.
    • install: install the package into the local repository, for use as a dependency in other projects locally
  23. Do I need to have a command prompt?
  24. Not really. At least I prefer getting thing done form the IDE instead of switching back and forth in any other window. It can be directly integrated with most of the IDEs and I will explain it for eclipse.

  25. How can I Integrate it in the eclipse?
  26. I have written details in this blog

Spring Integration -Getting started tutorial


A brief update, over past years I have continued working with spring integration and in quest to share my experience I have put challenges faced by me and it’s programmatic solution in a book name spring integration essentials which is available at amazon and packtpub. , and code samples at Github -please free to connect with me for any clarification or issues.

It’s NOT a theory book, you can directly dive into using code samples (they are available on Github, so you can try experimenting with them right away)

Let’s start with our Introduction 🙂
——————————————————————————————————————
I worked on one of the projects using spring integration. thought of sharing a quick hands on tutorial. I will cover following along with code snippet.

  1. Introduction
    • What problem does Spring Integration solves –Enterprise Application Integration
    • A brief overview of Spring Integration
    • What are alternatives
    • Why Spring Integration over other
  2. Getting Started
    • Main components (Message, Message Channel, Message End Point)
    • Message Endpoints (Transformer, Filter, Activator, Adapter)
  3. Scaling UP
    • How to implement multiple executors
  4. Infrastructural Support
    • JMX
  5. IDE -STS
  6. Basic hands On
    • A Example with REST based API and transformer
  • Introduction
  • Enterprise application have heterogeneous interfaces and applications, for example accounting, payroll, reporting, maintenance etc. which have been developed over a period of time with using different platforms (e.g. financial in COBOL, payroll in J2ee, maintenance in c/c++ etc. )

    Intercommunication between these modules have always been a challenge. How a c/c++ application talk with Java app, how CORBA and SOAP can be made seamless, how a File system and DB interaction be made possible -these all have been tried in multiple different ways. Enterprise Application Integration is an effort to address these kind of scenario.

      Major EAI approaches are

      • File Transfer: System interacts via files. For example an external provider can put files on a FTP
        server which contains input for other application.

      • Shared Database: Two systems interact via same database. For example in a SaaS environment,
        catalogue of product can be stored at same DB location which different vendors can use.
      • Remote Procedure Call: We see this everyday –Avatars are SOAP, REST most talked and “Hot”
      • Messaging: Two words- JMS architecture

    enterprise pattern defines major patterns for enterprise integration. Spring Integration is one of the implementation of the enterprise patterns.
    When we talk of heterogeneous communication, additional challenges comes in terms of synchronous and asynchronous communication mode. One of endpoints may not be available at time of interaction, or may be less responsive -this necessitates a need for an orchestrator which can retry, communication back, audit and do other stuff in role of a mediator. Here enters Enterprise Service Bus (ESB). ESB acts as mediator between these heterogeneous interfaces.

  • A brief introduction of Spring Integration:
  • Quoted from official Spring Integration
    “Spring Integration provides an extension of the Spring programming model to support the well-known Enterprise Integration Patterns. It enables lightweight messaging within Spring-based applications and supports integration with external systems via declarative adapters. Those adapters provide a higher-level of abstraction over Spring’s support for remoting, messaging, and scheduling. Spring Integration’s primary goal is to provide a simple model for building enterprise integration solutions while maintaining the separation of concerns that is essential for producing maintainable, testable code.”

  • Alternatives:
  • As discussed earlier, there have been numerous attempts to address the EAI. It’s difficult to list all –but two examples are.
    Mule ESB : It is a container, application need to be dropped in to leverage its support.
    Service Mix: It is another ESB, having a heavy footprint and trying to address lot of issues with lot of modules (OSGI Bundles)!
    Description of any of the above is beyond scope.

  • Why Spring Integration:
    • Does not need a container or separate process space, can be invoked in existing program
    • Very light footprint, it is just a JAR which can be dropped with WAR or standalone systems
    • spring framework module, goes easily with existing spring and java project
  • Getting started
    • An ESB must support following components

      • Routing: It should be able to route messages across different endpoints based on configured rules or conditional logic.
      • Messaging: Convert message to and from different incompatible format to a normalized format.
      • Mediation: Making communication possible between heterogeneous interfaces.
      • Complex Event Processing (CEP): Capability to listen for events and trigger it as well.
      • Invocation: It should be able to orchestrate service interaction and invocation.

    It should also support logging, auditing, authentication (security), and management, etc, above and beyond the services listed above.

  • What are the major components supported by Spring:
  • (Definitions and images are standard and taken from Spring Integration Reference. The purpose is to provide quick reference)
    Message
    In Spring Integration, a Message is a generic wrapper for any Java object combined with metadata used
    by the framework while handling that object. It consists of a payload and headers. The payload can be of any type and the headers hold commonly required information such as id, timestamp, correlation id, and return address.

    Message Channel
    A Message Channel represents the “pipe” of a pipes-and-filters architecture. Producers send Messages to a channel, and consumers receive Messages from a channel. The Message Channel therefore decouples the messaging components, and also provides a convenient point for interception and monitoring of Messages.
    A Message Channel may follow either Point-to-Point or Publish/Subscribe semantics. With a Point-to-Point channel, at most one consumer can receive each Message sent to the channel. Publish/Subscribe channels, on the other hand, will attempt to broadcast each Message to all of its subscribers.

    Should channels buffer the messages?
    Pollable Channels are capable of buffering Messages within a queue. The advantage of buffering is that it allows for throttling the inbound Messages and thereby prevents overloading a consumer.
    On the other hand, a consumer connected to a Subscribable Channel is simply Message-driven.

  • Message Endpoints
    A Message Endpoint represents the “filter” of a pipes-and-filters architecture. As mentioned above, the endpoint’s primary role is to connect application code to the messaging framework and to do so in a noninvasive manner. In other words, the application code should ideally have no awareness of the Message objects or the Message Channels. This is similar to the role of a Controller in the MVC paradigm. Just as a Controller handles HTTP requests, the Message Endpoint handles Messages. Just as Controllers are mapped to URL patterns, Message Endpoints are mapped to Message Channels.
    The goal is the same in both cases: isolate application code from the infrastructure.

    Typical endpoints:

    • Transformer
    • A Message Transformer is responsible for converting a Message’s content or structure and returning the modified Message. Probably the most common type of transformer is one that converts the payload of the Message from one format to another (e.g. from XML Document to java.lang.String).

      Typical use case : Convert XML and File based payloads to Domain objects.

    • Filter
    • A Message Filter determines whether a Message should be passed to an output channel at all. This simply requires a boolean test method that may check for a particular payload content type, a property value, the presence of a header, etc.

      Typical use case: Drop all message which does not meet the minimum criteria

    • Router
    • A Message Router is responsible for deciding what channel or channels should receive the Message next (if any).

      Typical use case: If a XML is parsed successfully, it is passed on to next channel for further processing else is routed on a retry channel.

    • Splitter
    • A Splitter is another type of Message Endpoint whose responsibility is to accept a Message from its input channel, split that Message into multiple Messages, and then send each of those to its output channel.

      Typical use case: After fetching list of files from a remote FTP server, list of files is put on a splitter, which then puts it on a gateway –one by one, so that each file can be fetched.

    • Aggregator
    • Basically a mirror-image of the Splitter, the Aggregator is a type of Message Endpoint that receives multiple Messages and combines them into a single Message. Spring Integration provides a completion strategy as well as configurable settings for timeout, whether to send partial results upon timeout, and the discard channel.

      Typical use case: PDF and related images are available from FTP server. Aggregator is used to wait for both (PDF and associated JPEG) of them to be available –correlation strategy decides if both are available or not. Once available it is passed on for further processing.

    • Service Activator
    • A Service Activator is a generic endpoint for connecting a service instance to the messaging system. The input Message Channel must be configured, and if the service method to be invoked is capable of returning a value, an output Message Channel may also be provided. The output channel is optional, since each message may also provide its own ‘Return Address’ header. This same rule applies for all consumer endpoints channel specified in the Message’s “return address” if available.

      Typical use case: All business processing done in service activator, for example persistence.

    • Channel Adapter
    • A Channel Adapter is an endpoint that connects a Message Channel to some other system or transport. Channel Adapters may be either inbound or outbound.
      An inbound “Channel Adapter” endpoint connects a source system to a MessageChannel

      An outbound “Channel Adapter” endpoint connects a MessageChannel to a target system.

    • Threading support:
    • Multiple instances of service activator can be configured to work on same channel. This will help in avoiding build up of channel. For optimal performance of threading, polling interval and max messages per poll should be set appropriately. Lets say, requirement is to process ~7k files in an hour–thread pool executor have been implemented to process items parallel y. A sample code:

    • Infrastructural Support
      • JMX
      • Sing line of configuration exposes all of the channels on standard JMX console.
      • Sample code snippet:
        • ‹context:mbean-server/›
        • ‹int-jmx:mbean-export id=”integrationMbeanExporter”/›

    • STS Visual Editor –
    • It can depict the Integration flow diagrammatically.

      • An in bound channel adapter post dummy message on trigger channel
      • HTTP outbound gateway listens on trigger channel and initiates a HTTP request as soon as channel gets some data
      • HTTP outbound gateway writes its response to HTTP response channel.
      • Transformer is connected to HTTP response channel, which transforms the message and passes on to a persister channel
      • Service Activator takes input from persister channel and performs business logic.
    • Basic hands On -A small code example
    • It is a code example as per above flow. Download the code hosted at Github. It is a maven project -download it and import it as a maven project. Details of class files:

      • Main.java : main class, this boots up the application.
      • InboundAdapter.java : Post dummy message on the trigger channel
      • SimpleTransformer.java :Transformer, which transforms the message –it just adds some custom string. It can be more meaning full as transforming to domain object.
      • HttpResponsePersisterService.java : Service activator –here business logic as persistence can go. For e.g. have just logged it in a log file.
      • spring-sample-app\src\main\resources\META-INF\application-context-root.xml : All the configurations for adapter, transformer and service activator here. Quite self explanatory
      • spring-sample-app\src\main\resources\log4j.properties : Log file settings.

      ——————————————————————————————————————
      A brief update, over past years I have continued working with spring integration and in quest to share my experience I have put challenges faced by me and it’s programmatic solution in a book name spring integration essentials which is available at amazon and packtpub. , and code samples at Github -please free to connect with me for any clarification or issues.

      It’s NOT a theory book, you can directly dive into using code samples (they are available on Github, so you can try experimenting with them right away)

DAY cq Author shuts down abruptly when it runs out of Space


We ran into a issue where an improper handling of an exception resulted in 100GB log and eventually causing out of space on DAY CQ author. On being out of space server shutdown abruptly. There is option in day cq to avoid this kind of corruption

  • CLOSE (default): The repository is shut down.
  • WAIT: The repository will block operations until sufficient disk space becomes available again.
  • THROW:Repository operations will throw an exception.
  • Sourced from here

All of sudden build failing in FLEX -Problem: failed to create task or type mxmlc


I upgraded JAVA version and after that all of a sudden FLEX project stopped compiling. It started throwing following errors:

C:\workspace\CSB_d3csb52\Source\build.xml:93: Problem: failed to create task or type mxmlc
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

I spend quite a time fixing this issue, so decided to put it here so that some one else might find it and save time -I found two reasons at two different occasion for this:

  • If it’s a ant script build, verify in the build.properties that SDK location is specified appropriately.
  • Open flex build setting (right click build.properties and select properties). On JRR tab, make sure that build is set to run in same JVM as flex. If it’s configured to run in separate JVM, then also this issue is encountered
  • Select same JVM for compiling

    OSGI -Ahh! not for a quicker adoption..”Adoption” curve is steep


    DISCLAIMER : This is in no way a reflection on OSGI as suitable/unsuitable framework, just my personal opinion as I found it having a steep learning curve which cannot be done in hurry

    We were evaluating technologies for one of our recent project which has a quite strict deadline (as usual ;)). One of the requirement was to push updates without any down time. OSGI was suggested, which allows bundles to be pushed without any restart of server. A little research helped us to understand it’s basic philosophy of bundles, restricted import and export, “forced” modularity -All seemed too good theoretically to be excited about using it and add to it that one of the most popular IDE eclipse uses OSGI.

    We started with the development, but as we expanded and added dependencies -its started turning out a nightmare. Most of the problem lied in one root cause -OSGI complaint jar for most of popular apps is not available out of box (example hibernate).

    Every module is a jar file – and for it to be OSGI complaint, it’s manifest should have enough information so that any OSGI container (like felix) can understand what packages does it import/export, what are run time dependencies and all. There are tool like BND which help convert non OSGI jars to OSGI jars, there are some repositories which have a collection of many standard libs like ebr.springsource.com -but it was lacking for one or other reason.

    If one searches at ebr.springsource.com, most of the libraries are older version. Although BND can add necessary information to metadata, we have to convert the whole dependency tree to an OSGI complaint.

    If any of the jars uses class.forname to load any class, for example JDBC jars, life becomes even miserable -There are a lot of class loader issues as soon as dynamic loading kicks in.

    Some of the issues which we encountered and which left a real sour taste:

    • Sling Scheduler Integration with Felix: Lack of proper documentation.

    We did not found proper documentation on installing sling. We felt, Felix website is NOT a “uptodate” source of documentation and only after looking out on community we were able to find exact steps.

    Solution: Getting exact steps helped and we were able to deploy it.

    • Quartz scheduler Job Store Integartion: Class loading issues.

    If Quartz is configured to use the Data store, it uses class.ForName to load the Data base driver dynamically. While attempting this it was throwing class not found exception.

    Solution:
    We used bnd tool to convert non OSGI complaint jars to OSGI complaint Jar.
    Added Dynamic-ImportPackage: * tag to look for classes through all bundles at run time.

    • Spring Web template for SOAP services: Class loading issues.

    We used Spring template for Java standalone project and it worked just fine. We tried to take same approach in OSGI environment i.e. Felix it failed. We picked up appropriate versions from spring source repository, but it did not helped. Following is a stack trace

    org.springframework.beans.factory.BeanInitializationException: Could not find default strategy class for interface [org.springframework.ws.transport.WebServiceMessageSender]; nested exception is java.lang.    at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategies(DefaultStrategiesHelper.java:126)    at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategies(DefaultStrategiesHelper.java:90)    at org.springframework.ws.client.core.WebServiceTemplate.initMessageSenders(WebServiceTemplate.java:320)     at org.springframework.ws.client.core.WebServiceTemplate.initDefaultStrategies(WebServiceTemplate.java:306)    at org.springframework.ws.client.core.WebServiceTemplate.<init>(WebServiceTemplate.java:143)
            at test.soapservice.service.SOAPServiceImpl.<init>(SOAPServiceImpl.java:41)
            at test.soapservice.service.SOAPServiceActivator.start(SOAPServiceActivator.java:17)
            at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:641)
            at org.apache.felix.framework.Felix.activateBundle(Felix.java:1977)
            at org.apache.felix.framework.Felix.startBundle(Felix.java:1895)
            at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191)
            at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)
            at java.lang.Thread.run(Thread.java:595)
    Caused by: java.lang.ClassNotFoundException: org.springframework.ws.transport.http.HttpUrlConnectionMessageSender
            at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    

    Solution: NONE

    • Connect standalone Felix instance with CRX repository using Jack Rabbit API.

    We tried accessing remote CRX repository using Jack Rabbit client for JCR complaint repository (in this case CRX) .

    Following are the problems we faced:
    To access the JCR repository we need “JCRUtils” with version 2.0 or above that is not available bundled in jar that is OSGi compliance. We have used tools BND(http://www.aqute.biz/Code/Bnd) and magen(http://felix.apache.org/site/apache-felix-manifest-generator-mangen.html) to make external non OSGi jars to OSGi jars (but this approach is not working due to incompatible version or cyclic dependency between two jars)
    To overcome this we have created a bundle in which we have bundled all the jars required to run above code with that bundle –using BundleClassPath meta tag. But the bundle deployed on Felix had problems like:
    incompatible version problem
    if jars bundled inside parent bundle have dependency on each other then we are getting NoClassDefFound error.
    We were able to access JCR repository by creating a simple java project contains following code using following libraries.

    So for sure its an OSGI specific issue.

    Solution: NONE

    After so much of hiccups and already spend an week of our development sprint, we decided to move on with custom approach and abandoned OSGI.

    May will take a detailed look in some free time, learn it properly and then try out the things. Mean while I am posting this experience so that it might help in planning for the bootstrap time line for a new team 🙂

    Never use data which can be localized as part of business logic


    I was reviewing a code and came across something as

     
    public doSomeStuff(String shortMonthName){
     if(shortMonthName.equlaIgnoreCase("jan")){
     //do something}
    }
    

    .
    In this code client passes a month name based on which some logic is executed.

    At first it might look as whats wrong? hmm ..what if in future multilingual support is introduced -the month names will be localized and the client supplies equivalant of “jan” in a language other than english –it will simply fail.This is a very simplistic use case, but hope I make my point

    Never use data which can be localized as part of a business logic 

    Path parameter to FileInputStream


    A basic discovery about FileInputStream 🙂
    FileInput stream always takes a absolute path

    new FileInputStream("must be an absolute path")

    .. if a relative path is given and even if that relative path is added in the class path then also it will not work.

    Adding code in word press blog


    blog on word press about word press feature ;). I was having hard time how to put in XML code or HTML code directly inside my blog, after spending little time I came across this link http://en.support.wordpress.com/code/posting-source-code
    Idea is use “sourcecode” tag, which supports a lot of languages.

    	  			 
              [//sourcecode]
    

    Some of the supported languages

    actionscript3
    bash
    clojure
    coldfusion
    cpp
    csharp
    css
    delphi
    erlang
    fsharp
    diff
    groovy
    html
    javascript
    java
    javafx
    matlab (keywords only)
    objc
    perl
    php
    text
    powershell
    python
    r
    ruby
    scala
    sql
    vb
    xml

    Moving property files outside jar in spring standalone application


    In one of Spring standalone project, we needed to move the property files out of the jar for easy configurability.
    I followed following steps:
    1. Move property files out of JAR and put in a directory say “target/lib”

    		<plugin>
    	           <artifactId>maven-antrun-plugin</artifactId>
    	           <executions>
    	             <execution>
    	               <phase>validate</phase>
    	               <goals>
    	                 <goal>run</goal>
    	               </goals>
    	               <configuration>
    	                 <tasks>
    				<copy todir="target/lib" overwrite="true">
    					<fileset dir="src/main/resources/">
    						<include name="*.properties"/>
    						<include name="*.xml"/>
    					</fileset>
    				</copy>
    	                 </tasks>
    	               </configuration>
    	             </execution>
    	           </executions>
            	 </plugin>
    

    2. Exclude inclusion of files from the JAR. This will include only .hbm files in resource and any XML file in META-INF (I wanted to keep application-context.xml used by spring inside JAR)

    			<resource>
    				<directory>${basedir}/src/main/resources</directory>
    				<filtering>true</filtering>	
    				<includes>
    					<include>**/*.hbm.xml</include>
    					<include>META-INF/*.xml</include>
    				</includes>
    			</resource>
    

    3. Use maven-jar plugin to include class path information in MANIFEST.MF. This one is MOST important

    	        <plugin>
    	            <groupId>org.apache.maven.plugins</groupId>
    	            <artifactId>maven-jar-plugin</artifactId>
    	            <configuration>
    	                <archive>
    	                    <manifest>
    	                        <addClasspath>true</addClasspath>
    	                        <classpathPrefix>lib/</classpathPrefix>
                                           <mainClass>
                                                 com.usat.digitalportal.service.impl.BootStrap
                                            </mainClass>
    	                    </manifest>
    	                    <manifestEntries>
               					 <Class-Path>. lib</Class-Path>
            			</manifestEntries>
    	                </archive>
    	            </configuration>
    	        </plugin> 
    

    a. Use “classpathPrefix” to specify folder name in which all properties will be placed.
    b. Use “Class-Path” to specify the folder. “.” Indicate current folder, while “lib” specifies “lib” folder in same directory as JAR (I have used lib).
    4. Changes in spring application-context.xml
    a. Add line to look for property file in declared class path

    <context:property-placeholder location="classpath*:**/settings.properties, classpath*:**/usat.properties” />	   
    

    b. Add line to import resources from class path

    		<import resource="classpath*:**/dao-config.xml"/>	 
    

    This is all which is needed. Run maven target as –X clean install and it should Generate a lib folder