Home Navigation

Sunday 3 December 2017

Maven: How to create multiple jars from a single maven project ( maven-jar-plugin)

Two produce multiple jars from a single module project you may use maven-jar-plugin. It is pretty simple to use. In prepare-package phase under configuration you can put your configuration.

below a sample xml file.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>build-business-jar</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifestFile>${basedir}/META-INF/MANIFEST.MF</manifestFile>
</archive>
<includes>
<include>com/**/*</include>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>com/exclude4/**/*</exclude>
</excludes>
<finalName>jarfilename2</finalName>
</configuration>
</execution>
<execution>
<id>build-webservices-jar</id>
<goals>
<goal>jar</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<includes>
<include>com/walmart/**/*</include>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>com/exclude1/**/*</exclude>
<exclude>com/exclude2/**/*</exclude>
<exclude>com/exclude3/**/*</exclude>
</excludes>
<finalName>jarfilename2</finalName>
</configuration>
</execution>
</executions>

</plugin>

Eclipse editor won't open, Error: Plug-in org.eclipse.ui.editors was unable to load class org.eclipse.ui.editors.text.TextEditor

You might face this problem at the time of editing a jsp, xml or even a text to edit. You will be shown an error page Error: Plug-in org.eclipse.ui.editors was unable to load class org.eclipse.ui.editors.text.TextEditor

To resolve this issue you may try one of the option below.

- YOUR_WORKSPACE/.metadata/.plugins/org.eclipse.jdt.core/ There are a lot of index files, remove all of the index files
- Start eclipse with -clean option

Wednesday 29 November 2017

Maven ant run plugin to execute ant command from maven

The example here for scp (secured copy) using ant in maven. One of the tip for this example you declare your dependency inside the plugin tag.



<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>1.8</version>
<executions>
   <execution>
<id>get-ear-from-nexus</id>
<phase>validate|clean|package|</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<scp file="file_name"
todir=" "
verbose="true" password=" " trust="true"
/>
</target>
</configuration>

</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
</plugin>

How to add multiple source file for a maven project

You might sometimes encounter a problem working with multiple source directory for a maven project. we are used to work with single source directory eg: src. what if you have src1, src2. src3 ..

Tor resolve this issue you can use maven helper build plugin.

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>build-helper-maven-plugin</artifactId>
   <version>1.9.1</version>
   <executions>
   <execution>
   <id>add-source</id>
   <phase>generate-sources</phase>
   <goals>
<goal>add-source</goal>
   </goals>
   <configuration>
   <sources>
   <source>
${basedir}/src1
   </source>
   <source>
${basedir}/src2
   </source>
   </sources>
   </configuration>
   </execution>
   </executions>
</plugin>

BDD feature/scenario execution via command line

Run all scenarios
      mvn clean test

Run specific feature file
     mvn clean test -Dcucumber.options="src/test/resources/feature/_file_name.feature"

Run specific scenario within feature file
    mvn clean test -Dcucumber.options="src/test/resources/feature/_file_name.feature:7"
    :7 - line# of the desired scenarios

Run specific scenarios within feature file
     mvn clean test -Dcucumber.options="src/test/resources/feature/_file_name.feature:7:20"

Run scenario by tag
     mvn clean test -Dcucumber.options="--tags @test"

Exclude specific tags from execution
    mvn clean test -Dcucumber.options="--tags @reports, -@tags ~@smoke"


Available environment to execute against – Dev, Test
   mvn clean test –Dcucumber.options=”--tags @test” –P test
   mvn clean test –Dcucumber.options=”--tags @test” –P dev

Friday 27 October 2017

What is BDD? TDD vs BDD

What is BDD?

BDD emerged from the process known as test-drive development (TDD). The concept behind BDD is to provide development and management teams with a shared process and tools to collaborate effectively while developing software. The developers wrties scenarios using Gherkin ( Ubiquitous language) and get feedbacks from the stakeholders.

Unit tests often help to reveal "small and stupid" mistakes in the code. The absence of unit tests would make me worry about underlying quality. When my unit test fails, I can quickly find the cause of this failure (at least, I know what part of my code contains a mistake). When my behavioral test fails, I sometimes need a little of debugging to find the cause. Also behavioral tests tend to cover "happy paths" (there is a tendency to miss them out) only. But they're the most useful when we need to refactor an old system with tons of legacy code, so... I think, TDD and BDD are like left and right hand for right-hander: you use your right hand more often and its fine motor skills are better, but it's kinda difficult to live without a left hand, too.

TDD vs BDD

TDD:

  • Focus: TDD is an "inside-out" process, the focus is on quality
  • Mostly written by developers
  • Specificity: When I test a spark plug in isolation - and the test fails - I know that spark plug is faulty. When a Unit Test fails, you know exactly what has failed.
  • Speed: A Unit Test is a test of a component in isolation. This may require mocking of (potentially slow) external dependencies. As a result, Unit Tests are super-quick to run.
  • 100% code coverage is a rare/difficult
  • Write to test each unit of codes, functions, class
  • Design to test low level scenarios

BDD:

  • Focus: BDD is an "Outside-in" process. The focus is on value.
  • Who writes the tests? The plain English format means that the tests can be written by the person that understands the customer best: the Product Owner. Who reads the tests? Almost anyone: Developers, Testers, Stakeholders, Business Owner, Product Owner.
  • Specificity: When my motorbike doesn’t start, I know that something is wrong. But I don’t know what is wrong.
  • Speed: Behavioral Tests are tests of the system as a whole. The system must be “put into a known state” before each and every test. Not particularly difficult to do… but not quick either.
  • 100% code coverage is not uncommon
  • Design high level scenario to test expectation from software or workflow
  • Design normally for acceptance testing or testing automation
  • Communicational pattern like examples 
  • Solves cost of translation
Ref: http://www.DevelopmentThatPays.com

Tuesday 25 April 2017

Introduction to spring cloud platform

Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state). Coordination of distributed systems leads to boiler plate patterns, and using Spring Cloud developers can quickly stand up services and applications that implement those patterns. They will work well in any distributed environment, including the developer's own laptop, bare metal data centres, and managed platforms such as Cloud Foundry.

Spring cloud is based on Netflix OSS components. It integrates the Netflix components in the spring development environment using auto configuration and convention over configuration similar to the way Spring Boot works.


Operations Component
Netflix, Spring, ELK
Service Discovery server
Netflix Eureka
Dynamic Routing and Load balancer
Netflix Ribbon
Circuit Breaker
Netflix Hystrix
Monitoring
Hystrix dashboard and Turbine
Edge Server
Netflix Zuul
Central Configuration server
Spring cloud config server
OAuth 2.0 protected API’s
Spring Cloud +
Spring Security OAuth2
Centralized log analyses
Logstash, Elasticsearch, Kibana (ELK)


Friday 17 March 2017

Java collections comparison


HashMap
TreeMap
Ordering
It doesn’t maintain ordering
TreeMap  elements are sorted according to the natural ordering of its elements . If TreeMap objects can not be sorted in natural order than use compareTo() method to sort the elements of TreeMap object.
Implementation
Hashing
Red black tree
Null key
Can store null key
No null key
Null values
Many null values
Many null values
Performance
Constant time O(1) get and put, fast in performance.
TreeMap provides guaranteed log(n) time cost for the get and put method. Slow in comparison
Comparison
Uses equals method
Uses compareTo method
Interface
Map
Navigational Map
Similarities
Not thread safe, shallow copy, fail fast iterator

HashTable
HashMap
LinkedHashMap
Synchronized
Unsynchronized
It is a subclass of HashMap. It inherits all the features of HashMap. In addition linkedlist preserved the insertion order.
Doesn’t permit null key
Permits one null key

Thursday 16 February 2017

Maven's Non-Resolvable Parent POM Problem

Problem: [FATAL] Non-resolvable parent POM: Failure to find com.mycompany.samples:biometrics-samples:pom:4.2.0.0

Solution: Check if the maven installation is correct. Go to eclipse Window->Preference->Maven ->installations

Locate your external Maven installation directory

Then go to Maven->User settings and add the global settings.xml to {MAVEN_INSTALLATION}\conf\settings.xml and update and rebuild index.

Last step, right click on project -> mavne -> update projects and make sure to select force update option as well and click the button OK

It should resolve the issue.

Tuesday 24 January 2017

DB2, SQLState: 56038, Error Code -4743, -4700

Functions that this release of DB2 introduces cannot be used before new function mode has been enabled. An attempt was made to execute one of these functions. In addition, support for extending the length of a VARCHAR (supported in V7) is restricted in V8 until new function mode has been enabled.


This error you might get when your project was compiled, configured and deployed using webshpere version 7 and you are trying to compile and deploy in websphere 8.5

To solve the issue, create and map new jdbc connection from ear deployment descriptor.

Ear project->Deployment descriptor->deployment tab-> remove all the existing jdbc configuration and configure the jdbc and jndi mapping again with DB2.

Thursday 12 January 2017

A Resource reference binding could not be found for the jdbc/mydb resource CWNEN0044E

You need to add the binding in ibm-web-bnd.xml:

<resource-ref name="jdbc/mydb" binding-name="jdbc/jndi" />

jdbc/jndi: You will configure jndi in websphere admin console,
Reference name: resource-ref name should match with res-ref-name

<resource-ref>
    <res-ref-name>jdbc/mydb</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
 </resource-ref>

You should also make sure that <web-app version of web.xml file should be 2.5 or up and use schema not dtd. If you use older version of J2EE you have to use ibm-web-bnd.xmi file instead of xml.