Pages

Friday 12 July 2013

How to build a maven project job in Jenkins


How to build a maven project job in Jenkins


 Creating new job.



  • Select a New Job from the left menu bar.
  • Add the Job name specified in red box.
  • Select the radio button for building a maven2/3 project.
  • Click Ok.

 Configuring Project 


  • Add the Repository URL by selecting the Subversion (SVN) button.
  •  If you want to specify the folder name where all build process should be done, it can be entered in Local module directory.

Specifying the goals and Options.



  • You can set goals you want to execute followed by the Database options  -DDBUsername=<DB Username> -DDBPassword=<DB Password> -DDBUrl=<Database URL>”.
  • Click Save and Apply.                                                                                                                                                
References:-



Why to use Jenkins for CRON jobs.

Why Jenkins

Jenkins is an application which monitors executions of repeated jobs, such as building a software project or jobs run by cron.
  • Building/testing software projects continuously, just like CruiseControl or DamageControl. In a nutshell, Jenkins provides an easy-to-use so-called continuous integration system, making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. The automated, continuous build increases the productivity.
  • Monitoring executions of externally-run jobs, such as cron jobs and procmail jobs, even those that are run on a remote machine. For example, with cron, all you receive is regular e-mails that capture the output, and it is up to you to look at them diligently and notice when it broke. Jenkins keeps those outputs and makes it easy for you to notice when something is wrong. 

Meet Jenkins
Jenkins can be installed as:
  1. It can be installed as a windows service.
  2. Its war can be run through a command prompt.


Using Jenkins


Challenges in Jenkins

·       JUnit through Ant Script

When JUnit is run through Ant script, if you want to display the results in Jenkins, it is important the reports generated should be in XML format, because Jenkins only reads in XML format.

·       Memory leakage problem when JUnit is run through Maven.

Refer this link to resolve the problem.

References:




Thursday 11 July 2013

Difference between Spring Batch & Quartz Scheduler

Difference between Spring Batch & Quartz:

 Spring Batch and Quartz  have different goals. Spring Batch provides functionality for processing large volumes of data and Quartz provides functionality for scheduling tasks. So Quartz could complement Spring Batch, but are not excluding technologies. A common combination would be to use Quartz as a trigger for a Spring Batch job using a Cron expression and the Spring Core convenience SchedulerFactoryBean

Spring Batch Features

The first stable build was  released in January 30, 2009 (Ver. 1.1.4) ,From many years it is used by many companies.

                Spring Batch is a lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems. Spring Batch builds upon the productivity, POJO-based development approach, and general ease of use capabilities people have come to know from the Spring Framework, while making it easy for developers to access and leverage more advanced enterprise services when necessary.

Benefits of Using Spring Batch

  • Since the foundation of Spring Batch is based upon the Spring framework, you also get all of the benefits of Spring such as dependency injection and bean management based upon simple POJOs.
  • For developers already accustomed to developing Spring based applications, it’s a very short ramp up time getting familiar with using the Spring Batch framework.
  • The majority of the technical aspects surrounding the creation of batch applications have been solved and the developer instead spends more time solving the business needs.
  • By leveraging the additional functionality of Spring Integration, you can further increase the scalability of more distributed processes.


 
Quartz Features

Runtime Environments:
  • Quartz can run embedded within another free standing application
  • Quartz can be instantiated within an application server (or servlet container), and participate in XA transactions
  • Quartz can run as a stand-alone program (within its own Java Virtual Machine), to be used via RMI
  • Quartz can be instantiated as a cluster of stand-alone programs (with load-balance and failover capabilities)


Job Scheduling:
       Jobs are scheduled to run when a given Trigger occurs. Triggers can be created with nearly any combination of the following directives:

  • at a certain time of day (to the millisecond)
  • on certain days of the week
  • on certain days of the month
  • on certain days of the year
  • not on certain days listed within a registered Calendar (such as business holidays)
  • repeated a specific number of times
  • repeated until a specific time/date
  • repeated indefinitely
  • repeated with a delay interval
  • Jobs are given names by their creator and can also be organized into named groups. Triggers may also be given names and placed into groups, in order to easily organize them within the scheduler. Jobs can be added to the scheduler once, but registered with multiple Triggers. Within an enterprise Java environment, Jobs can perform their work as part of a distributed (XA) transaction.



Job Execution:

  •  Jobs can be any Java class that implements the simple Job interface, leaving infinite possibilities for the work your Jobs can perform.
  •  Job class instances can be instantiated by Quartz, or by your application's framework.
  • When a Trigger occurs, the scheduler notifies zero or more Java objects implementing the JobListener and TriggerListener interfaces (listeners can be simple Java objects, or EJBs, or JMS publishers, etc.). These listeners are also notified after the Job has executed.
  •  As Jobs are completed, they return a JobCompletionCode which informs the scheduler of success or failure. The JobCompletionCode can also instruct the scheduler of any actions it should take based on the success/fail code - such as immediate re-execution of the Job.


Job Persistence:

  •  The design of Quartz includes a JobStore interface that can be implemented to provide various mechanisms for the storage of jobs.
  • With the use of the included JDBCJobStore, all Jobs and Triggers configured as "non-volatile" are stored in a relational database via JDBC.
  • With the use of the included RAMJobStore, all Jobs and Triggers are stored in RAM and therefore do not persist between program executions - but this has the advantage of not requiring an external database.


Transactions:

  • Quartz can participate in JTA transactions, via the use of JobStoreCMT (a subclass of JDBCJobStore).
  • Quartz can manage JTA transactions (begin and commit them) around the execution of a Job, so that the work performed by the Job automatically happens within a JTA transaction.


Clustering:

  • Failover.
  • Load balancing.
  • Quartz's built-in clustering features rely upon database persistence via JDBCJobStore (described above).
  • Terracotta extensions to Quartz provide clustering capabilities without the need for a backing database.


Listeners & Plug-Ins:

  • Applications can catch scheduling events to monitor or control job/trigger behavior by implementing one or more listener interfaces.
  • The Plug-In mechanism can be used add functionality to Quartz, such keeping a history of job executions, or loading job and trigger definitions from a file.
  • Quartz ships with a number of "factory built" plug-ins and listeners.


Summary

 Quartz is a full-featured, open source job scheduling service that can be integrated with, or used alongside virtually any Java application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components that may execute virtually anything you may program them to do. The Quartz Scheduler includes many enterprise-class features, such as support for JTA transactions and clustering.

Who is using Quartz?

Quartz is in use by many thousands of entities, many of whom have directly embedded Quartz in their own custom applications, and others who are using products that already have Quartz embedded within them.

Quartz 1.6.0 was directly downloaded more than 100,000 times, and countless additional times through secondary repositories (such as ibiblio.org).

Here is a list of just a few of the thousands of Quartz users:
  • Vodafone Ireland - uses Quartz for scheduling tests to be carried out on systems in order to generate quality of service information.
  •  Covalent Technologies, Inc. - uses Quartz within their CAM product to handle anything scheduling related in the system, such as: scheduling server actions (start, restart, etc.), metric calculations, data cleanup daemons, etc.
  • Partnet Inc. - uses Quartz for scheduling application events and driving workflows within many of its products. Partnet has been a contributor to the Quartz code base in years past.
  • U.S. Department of Defense - uses Quartz at various points within a large electronic commerce application, notably order fulfillment.
  • Level3 Communications - uses Quartz to drive software builds and deployments.
  • Atlassian - uses Quartz within several of their excellent products, such as JIRA and Confluence.
  • Cisco - uses Quartz in various in-house systems.
  • Apache Jakarta - Quartz is used within (or as plugins to) several products falling under the Jakarta umbrella.
  • OpenSymphony - Uses Quartz to drive the OS Workflow product.
  • Spring - Quartz is used within the Spring Framework.
  • XpoLog - uses Quartz within XpoLog Center in order to enable automatic technical support.
  • Bloombase Technologies - has integrating Quartz within their Spitfire EAI Server for XML security processing.
  • Thomson Tax and Accounting - uses Quartz in its job scheduling framework within it's editorial systems group.
  • The Liferay Portal - is using the Quartz Scheduler. Just download and check the code. Liferay Inc. Portal.
  • Infoglue CMS - from infoglue.org
  • Apache Cocoon - uses Quartz to provide scheduling features and to run application background processes.
  • JBoss - uses Quartz for the implementation of a number of services within its infrastructure.
  • Adobe - uses Quartz for scheduling database operations in their LiveCycle Enterprise Suite.
  • Icebergsofts - uses Quartz for job scheduling in iceQA 2009.
  • Cypress Care Inc. - uses Quartz for all Insurance-related Job Scheduling for the organization
  • OpenReports - (http://oreports.com) - an open source web reporting application uses Quartz to schedule reports.
  • Ubik-Ingenierie - (http://www.ubik-ingenierie.com) uses Quartz in an in house Batch server for Java.
  • Apache Synapse - uses Quartz to add Job Scheduling to the Apache Synapse ESB. It is also being "inherited" by the WSO2 ESB which is another Open Source project that packages Apache Synapse.
  • Sun's OpenESB community - uses Quartz for the Scheduler component in the ESB that can be used in conjunction with a growing list of 40+ components such as RSS, FTP, SAP, CORBA, scripting engines, event processing, business process orchestration, etc.
  • Caucho - uses Quartz to power the scheduling features within their Resin Java EE 6 Web Profile implementation.
  • Adeptia - uses Quartz to provide scheduling and job management features within its Adeptia Suite line of ETL, Integration and Business Process Management products.
  • OpenSearchServer - (http://www.open-search-server.com) uses Quartz to provide scheduling features.



References:-

Spring Batch API



Quartz API

How to create DOCX file using DOX4J api using Java.

How to read the Word Template?


  1. A docx file is merely a zip-archive of xml files (plus any binary files for embedded objects such as images), we met that requirement by unpacking the zip file, feeding the document.xml to a template engine that does the merging for us, and then zipping the output document to get the new docx file.
  2. If we want to generate a doc file either Apache POI jar can be used but, how to read the xml & write in doc file or Jasper which reads the xml file and write to doc file. 
  3. Docx to docx conversion can be done by feeding the values in XML and save it by using docx4J jar.




What DOX4J can do?


  • Open existing docx (from filesystem, SMB/CIFS, WebDAV using VFS), pptx, xlsx.
  • Create new docx, pptx, xlsx.
  • Programmatically manipulate the above (of course) Specific to docx4j (as opposed to pptx4j, xlsx4j).
  • Template substitution; CustomXML binding.
  • Produce/consume Word 2007's xmlPackage (pkg) format.
  • Save docx to filesystem as a docx (ie zipped), or to JCR (unzipped).
  • Apply transforms, including common filters.
  • Export as HTML or PDF.
  • Difference/Compare documents, paragraphs or sdt (content controls).
  • Font support (font substitution, and use of any fonts embedded in the document).




Problems with Apache POI:-

Apache POI's HWPF can read .doc files, and docx4j could use this for basic conversion of .doc to .docx.
The problem with this approach is that POI's HWPF code fails on many .doc files.

What Approach we can use?

An effective approach is to use OpenOffice (via jodconverter) to convert the doc to docx, which docx4j
can then process. If you need to return a binary .doc, OpenOffice/jodconverter can convert the docx back to .doc.

There is also http://b2xtranslator.sourceforge.net/ . If a pure Java approach were required, this could be converted.



Some References : -

How to open and manipulate Word document/template in Java?

http://stackoverflow.com/questions/9379580/how-to-open-and-manipulate-word-document-templatein-java

Getting started with DOCX4J.
http://www.docx4java.org/svn/docx4j/trunk/docx4j/docs/Docx4j_GettingStarted.html

Working with Apache POI.
http://poi.apache.org/

Example awaited.