Friday, 4 December 2015

Accessing H2 in memory database

Accessing H2 in memory database integrated in spring application

Add below 2 beans in spring config. H2 console will be accessible on http://localhost:8082/

<bean id="h2Server" class="org.h2.tools.Server" factory-method="createTcpServer" init-method="start" destroy-method="stop" depends-on="h2WebServer">
<constructor-arg value="-tcp,-tcpAllowOthers,-tcpPort,9092"/>
</bean>
<bean id="h2WebServer" class="org.h2.tools.Server" factory-method="createWebServer" init-method="start" destroy-method="stop">
<constructor-arg value="-web,-webAllowOthers,-webPort,8082"/>
</bean>

Friday, 20 November 2015

String with variable parameters

Using string with parameters is very handy in case of Constants.

Java class in focus is: java.text.MessageFormat
import java.text.MessageFormat;

public class Welcome {
public static void main(String[] args) {
System.out.println(MessageFormat.format(Constants.WELCOME, "Mr", "Nikhil"));
System.out.println(MessageFormat.format(Constants.WELCOME, "Mrs", "Tejashree"));
}

/**
* Constants class.
*/
public final class Constants {
private Constants() {
}

/**
* Welcome message.
*/
public static final String WELCOME = "Welcome {0}. {1} to njoshi.com";
}
}

 

Output will be

Welcome Mr. Nikhil to njoshi.com
Welcome Mrs. Tejashree to njoshi.com

Friday, 9 October 2015

Installing VirtualBox guest additions on CentOS or RHEL

Process is very simple

  1. Login as root

  2. Install dependencies # yum install gcc make kernel-headers kernel-devel

  3. Reboot for loading new kernel info if required and to be on safer side

  4. Use gmake instated of make #export MAKE='/usr/bin/gmake -i'

  5. Insert guest additions CD

  6. goto installer # cd /media/VBOXADDITIONS*

  7. #./VBoxLinuxAdditions.run

  8. Reboot and enjoy

Tuesday, 22 September 2015

Monday, 7 September 2015

Creating multiple jars from single pom file

In ant we can create any number of jars using <jar> tag, but when we are moving to maven from ant it we may face challenge. Old code may not be modular imposing use of single pom file. In this case maven-jar-plugin come to rescue.

maven-jar-plugin

I guess xml is self explanatory, if question put it in comments
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>first-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<finalName>first-jar</finalName>
<includes>
<include>**/njoshi/**/first/**/*.class</include>
</includes>
<archive>
<index>false</index>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.njoshi.research.multiplejars.first.FirstJarSampleClass</mainClass>
</manifest>
<manifestEntries>
<url>${project.url}</url>
<Implementation-Title>com.njoshi.research.multiplejars</Implementation-Title>
<Implementation-Vendor>Nikhil Joshi</Implementation-Vendor>
<version>${project.version}</version>
<Implementation-Version>
<configuration>
<format>{0,date,yyyyMMddHHmmss}</format>
<items>
<item>timestamp</item>
</items>
</configuration>
</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</execution>
<execution>
<id>second-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<finalName>second-jar</finalName>
<includes>
<include>**/njoshi/**/second/**/*.class</include>
</includes>
<archive>
<index>false</index>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.njoshi.research.multiplejars.second.SecondJarSampleClass</mainClass>
</manifest>
<manifestEntries>
<url>${project.url}</url>
<Implementation-Title>com.njoshi.research.multiplejars</Implementation-Title>
<Implementation-Vendor>Nikhil Joshi</Implementation-Vendor>
<version>${project.version}</version>
<Implementation-Version>
<configuration>
<format>{0,date,yyyyMMddHHmmss}</format>
<items>
<item>timestamp</item>
</items>
</configuration>
</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Full working source code

Wednesday, 12 August 2015

Getting Started With Activiti and Spring Boot

Very good article on Getting Started With Activiti and Spring Boot by Activiti co-founder Joram Barrez
http://java.dzone.com/articles/getting-started-activiti-and

Sunday, 22 March 2015

Getting Started With Activiti and Spring Boot

Very good article on Getting Started With Activiti and Spring Boot by Activiti co-founder Joram Barrez

http://java.dzone.com/articles/getting-started-activiti-and