I have a maven based java web application running locally on the jetty server, I would like to debug the application.

Here are the steps I followed to make it happen.

  • Enable server socket address (9999) at the server side.
  • Enable Remote Java Application to bind to that address (9999).


1.Declare the maven-jetty-plugin on POM.xml as shown below.


pre style=”padding-left:60px;”>

 <!-- Jetty server plugin -->
2.  click on Run As --> External Tool Configurations as shown below.


This will bring up another window as shown below. click new to create a new configuration !

eclipse-maven-jetty-debug- external-tool-configuration

* Location: The executable file of maven , (usr/bin/mvn is for ubuntu OS.)

* Working directory: The current project working directory.

* Arguments: jetty:run 

   3. Click on Environment Tab and add a new Environment Variable as shown below.



-Xdebug -agentlib:jdwp=transport=dt_socket,address=9999,server=y,suspend=n

Now click Apply and Run to start the jetty server, also server will be listening on port 9999 for remote debugging.

  4. Now click on Debug As --> Debug Configurations as shown below.


 5. Click on Remote Java Application and click new to create a new configurations. 
   This should bring up a new window as shown below.


Make sure to give the correct port,name, host etc. 
6. Click on the common Tab to add this configuration to the favourite menu of Debug As.


Now you should be able to debug the application by placing few breakpoints in the java source code.



Barcode Generator in Java

I was asked to work on generating barcode labels for one of projects. I searched online and found many free java projects which would help me in achieving my task.

Here is the few i got via google search:


Finally i have decided to go with barcode4j as it is available under Apache Licence V2.

I have built a jar file using the source of barcode4j and kept it in a lib folder of my project.

As i am using Maven for building my project on heroku for a demo purpose,  I need to keep this jar locally , so that heroku build structure will be able to understand the local jar (barcode4j.jar).

I have followed the below steps to include the local jar in my  project in such a way that the maven build will make use of this library for solving dependencies.

I followed the above link for making available local maven dependencies.


The source code is available in the heroku git repository here

The live demo is available here




Smartclient RestDatasource (ListGrid )using JAX-RS as JSON Data service

This is for beginners who likes to understand the smartclient RIA using JAVA as JSON service.

Smartclient LPGL version does not ship with smartclient server , so we need to manually create server side datasources for all of our Databound UI components.

Say I have downloaded the smartclient LPGL version from isomorphic website. Now I would like to add ListGrid  library to my web application. Here is sample grid we are going to build here. The tutorial application is hosted in Click here to access it




Here are the few things i did to make this work.

  • Create the RestDataSource with the JSON date format (id, structure fields, date format, data urls).
  • Create UI-controls (Data grid, add, remove and delete controls).
  • Create a JSON Webservice for the above CRUD Operations
  • Run it (download smart client sdk LPGL version and run example in an atachment).


The complete source code for this grid (UI) and Server side implementation(JAX-RS) for CRUD operations are available in the github here.




Failed to execute goal on project core: Could not resolve dependencies for project com.mycompany:core:jar:1.0: Could not find artifact at specified path C:\Program Files\Java\jre7/../lib/tools.jar ->

Hi ,

When i tried to install the broadleaf commerce on my local machine i was facing this error.

Failed to execute goal on project core: Could not resolve dependencies for project com.mycompany:core:jar:1.0: Could not find artifact at specified path C:\Program Files\Java\jre7/../lib/tools.jar ->

You will need a Java JDK not just a JRE.



Also I have added tools.jar as dependencies in the POM.xml of ecommerce-core (parent) module as below. Alternative way is to install this jar locally using mvn install command.


Test execution order – JUnit 4.X

I want to execute test methods which are annotated by @Test in specific order.

For example:

public class MyTest{
    @Test public void create(){System.out.println("create");}
    @Test public void update(){System.out.println("update");}
    @Test public void delete(){System.out.println("delete");}

I want to ensure to run create() before update() and updatebefore delete each time I run MyTest.

The test execution order i would like to get is,


Test execution order

By design, JUnit does not specify the execution order of test method invocations. Until now, the methods were simply invoked in the order returned by the reflection API. However, using the JVM order is unwise since the Java platform does not specify any particular order, and in fact JDK 7 returns a more or less random order. Of course, well-written test code would not assume any order, but some does, and a predictable failure is better than a random failure on certain platforms.

From version 4.11, JUnit will by default use a deterministic, but not predictable, order (MethodSorters.DEFAULT). To change the test execution order simply annotate your test class using @FixMethodOrder and specify one of the available MethodSorters:

@FixMethodOrder(MethodSorters.JVM): Leaves the test methods in the order returned by the JVM. This order may vary from run to run.

@FixMethodOrder(MethodSorters.NAME_ASCENDING): Sorts the test methods by method name, in lexicographic order.


import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

public class MyTest {
	public void aCreate() {

	public void bUpdate() {

	public void cDelete() {

This would produce the output as i wanted.

Result Aggregation using JUnit- Rule (Testwatcher)

Hi All,

I was asked to create a custom JUnit test result file which only has test case name and pass/failure message.

result.txt should contain like mentioned below.

testmethod1 : success
testmethod2 : failed
testmethod3 : success
testmethod4 : success

1. Result Aggregation:

The challenge is , we can not log the test results within the test method itself because at this time we will not be able to know whether the test will pass or fail. You may think ,we can write a log statement at the end of the test method but that will log only the success test methods, what about theFailed/Ignored/Errors test methods? As soon as assert failed , AssertionError will be thrown by the Junit and we will not be having any control to log this anywhere.. Still you may think, you can catch this exception and write a log statement and then fail the test methods. Yeah , this would work but it has some drawbacks.

  1. we will not be able to capture the ignored tests.
  2. we will not be able to clearly classify Errors vs Failures (these are completely different)
  3. we need to write a try/catch block in all of our tests. More customization required.

The above functionlity can be achieved easily using TestWatchmen Rule provided by JUnit-Framework.

JUnit-4.9 introduced new features called "Rule" which can be used to keep a log of each passing, ignored, failing tests. Click here for more information

With this approach we need to do no modification to the existing code still we can do our result aggregation.

Step 1: Create a class which implements TestRule Interface.


import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;


public class ResultAggregator extends TestWatcher {

	private static String resultLog = "";
	private LoggerUtility loggerUtil = null;

	ResultAggregator() {
		// TODO need to refactor this constructor
		loggerUtil = LoggerUtility.getInstance();

	public Statement apply(Statement base, Description description) {
		return super.apply(base, description);

	protected void succeeded(Description description) {
		resultLog = description.getMethodName() + ": " + "SUCCESS \n";

	protected void failed(Throwable e, Description description) {
		resultLog = description.getMethodName() + ":  " + "FAILED " + "\n";

	protected void starting(Description description) {

	protected void finished(Description description) {



This class will keep a log of each passing and failing test:

Step 2: Create test class and add @Rule annotations.


import static;

import org.junit.Rule;
import org.junit.Test;

public class ResultAggregatorTest {

	public ResultAggregator log = new ResultAggregator();

	public void testmethod1() {


	public void testmethod2() {


If you execute the above test class you will get an output as shown below.

testmethod1 : SUCCESS

testmethod1 : FAILED

Note: LoggerUtil is the class which is an custom defined logger for logging different files using log4j.

2. Repeat test with different input files.

We could achieve this by extending Junit-Core Runners [Junit-4X runners , Junit3X runners will be compatible with annotations] and iterate it with our files. I understood that this runner [] are provided by JUnit itself in the recent releases. Click here to know more about Parameterized-tests