Archive for the ‘JAVA’ Category

Play! Framework – Deployment using Jenkins [Create Jobs]

August 31, 2015 1 comment

For the first time, you can click on create new jobs at home page. Or you can click New Item.
Choose Freestyle project and fill Item name, click Ok.

home_loginCreate job
Adding build parameter, I want to build specific branch, so I added git parameter

git parameterBuildParameter

In source code management I choose git then fill the config.


In section Build, choose Invoke Play! Framework. We can see this choice if we already installed the plugin. Fill the config. Play!Framework Installation choice will appear if we already configure Play! in Configure System.

build play


The last step is configure Post-build Actions, I want to sent the artifact.


You must configure ssh server in Configure System.

Categories: Jenkins, Play! Framework

Downloading Java JDK on Linux via wget

Use this command for download Oracle JDK 8u60

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"

This wget essentially passes a cookies which pretends user has accepted the agreement

Categories: JAVA, Ubuntu

Play! Framework – Deployment using Jenkins [Installation and Configuration]

System requirement:

  • Java 7 or higher


  1. Jenkins installation
    sudo wget -O /etc/yum.repos.d/jenkins.repo
    sudo rpm --import
    sudo yum install jenkins
  2. Add jenkins to startup and then start
    sudo chkconfig jenkins on
    sudo service jenkins start
  3. Check if Jenkins had been running, go to http://your_ip:8080/


  4. Configure JDK
    Go to Manage Jenkins – Configure System. In JDK section set java home.
    Set JDK
  5. Add ssh configuration (for git)
    cd /var/lib/jenkins/
    sudo mkdir .ssh
    sudo nano config

    Fill config file with

    Host repo your_git_ip
        HostName your_git_ip
        IdentityFile /var/lib/jenkins/.ssh/your_git_key
        User your_git_username

    Tes ssh config

    sudo su -s /bin/bash jenkins
    git ls-remote -h ssh://your_git_username@your_git_ip/your_git.git HEAD

    If result is are “too open”, change your_git_key permission to 600
    Change owner of config and key

    sudo chown jenkins:jenkins your_git_key
    sudo chown jenkins:jenkins config
  6. Get activator
    download activator


    unzip to /opt and change owner jenkins:jenkins

    chown jenkins:jenkins -R activator-1.3.5-minimal/

    Read more…

Categories: Jenkins, Play! Framework

Installing Oracle JDK on Ubuntu

March 8, 2015 1 comment

This tutorial will cover the installation of 64-bit Oracle Java 7 (7.0_75)

  1. Check to see if your Ubuntu system architecture is 32-bit or 64-bit, mine is 64 bit. Open up a terminal and run the following command below.
    bluething@ubuntu:~$ file /sbin/init
    /sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=7a4c688d009fc1f06ffc692f5f42ab09e68582b2, stripped
  2. Check if you have Java installed on your system. Mine doesn’t have any Java installed.
    bluething@ubuntu:~$ java -version
    The program 'java' can be found in the following packages:
    * default-jre
    * gcj-4.8-jre-headless
    * openjdk-7-jre-headless
    * gcj-4.6-jre-headless
    * openjdk-6-jre-headless
    Try: sudo apt-get install <selected package>

    If you have Java installed on your system, the command should return like this, for Ubuntu default Java is OpenJDK.

    java version "1.7.0_15"
    OpenJDK Runtime Environment (IcedTea6 1.10pre) (7b15~pre1-0lucid1)
    OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)

    If you have Java installed on your system, remove the OpenJDK/JRE with the following command.

    sudo apt-get purge openjdk-\*
  3. Create a directory to hold your Oracle Java JDK/JRE binaries.
    bluething@ubuntu:~$ sudo mkdir -p /usr/local/java
    [sudo] password for bluething:
    bluething@ubuntu:~$ ls -l /usr/local
    total 36
    drwxr-xr-x 2 root root 4096 Apr 16 2014 bin
    drwxr-xr-x 2 root root 4096 Apr 16 2014 etc
    drwxr-xr-x 2 root root 4096 Apr 16 2014 games
    drwxr-xr-x 2 root root 4096 Apr 16 2014 include
    drwxr-xr-x 2 root root 4096 Mar 8 05:44 java
    drwxr-xr-x 4 root root 4096 Apr 16 2014 lib
    lrwxrwxrwx 1 root root 9 Mar 8 01:56 man -> share/man
    drwxr-xr-x 2 root root 4096 Apr 16 2014 sbin
    drwxr-xr-x 7 root root 4096 Apr 16 2014 share
    drwxr-xr-x 2 root root 4096 Apr 16 2014 src
  4. Download the Oracle Java JDK/JRE for Linux, you can find here. Make sure you select the correct compressed binaries for your system architecture 32-bit or 64-bit. I put on home directory.
  5. Unpack the compressed Java binaries to the directory /usr/local/java.
    bluething@ubuntu:~$ sudo tar xvzf jdk-7u75-linux-x64.tar.gz -C /usr/local/java
    bluething@ubuntu:~$ sudo tar xvzf jdk-8u40-linux-x64.tar.gz -C /usr/local/java
    bluething@ubuntu:~$ ls -l /usr/local/java
    total 8
    drwxr-xr-x 8 uucp 143 4096 Dec 18 17:04 jdk1.7.0_75
    drwxr-xr-x 8 uucp 143 4096 Feb 10 21:42 jdk1.8.0_40
  6. Edit the system PATH file /etc/profile and add the following system variables to your system path. I’m using gedit.
    export JAVA_HOME
    export JRE_HOME
    export PATH
  7. Inform your Ubuntu Linux system where your Oracle Java JDK/JRE is located.
    bluething@ubuntu:~$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_75/bin/java" 1
    update-alternatives: using /usr/local/java/jdk1.7.0_75/bin/java to provide /usr/bin/java (java) in auto mode
    bluething@ubuntu:~$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_75/bin/javac" 1
    update-alternatives: using /usr/local/java/jdk1.7.0_75/bin/javac to provide /usr/bin/javac (javac) in auto mode
    bluething@ubuntu:~$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.7.0_75/bin/javaws" 1
    update-alternatives: using /usr/local/java/jdk1.7.0_75/bin/javaws to provide /usr/bin/javaws (javaws) in auto mode
  8. Inform your Ubuntu Linux system that Oracle Java JDK/JRE must be the default Java.
    bluething@ubuntu:~$ sudo update-alternatives --set java /usr/local/java/jdk1.7.0_75/bin/java
    bluething@ubuntu:~$ sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_75/bin/javac
    bluething@ubuntu:~$ sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_75/bin/javaws
  9. Reload your system wide PATH /etc/profile.
    bluething@ubuntu:~$ . /etc/profile

    Reboot Ubuntu

  10. Test to see if Oracle Java was installed correctly on your system.
    bluething@ubuntu:~$ java -version
    java version "1.7.0_75"
    Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)


Categories: JAVA, Ubuntu

Send logs by Email Notification using Apache log4j SMTPAppender

February 15, 2015 Leave a comment

Apache log4j provides log Appender (called SMTPAppender) to send email alerts for the log level configured in log4j configuration file. For example I using simple struts 2 application.


<project xmlns="" xmlns:xsi=""
 <name>SimpleStruts2 Maven Webapp</name>







Read more…

Categories: JAVA



Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence “The quick brown fox jumps over the lazy dog” repeatedly because it is a pangram. ( pangrams are sentences constructed by using every letter of the alphabet at least once. ) After typing the sentence several times, Roy became bored with it. So he started to look for other pangrams. Given a sentence s, tell Roy if it is a pangram or not.

From Wikipedia, A pangram or holoalphabetic sentence for a given alphabet is a sentence using every letter of the alphabet at least once. Check both uppercase and lowercase(+32).

Using Java String function indexOf() to check if the character appear in the sentence.

Java code:

import java.util.Scanner;

public class Pangram {

public static void main(String[] args) {
 Scanner in = new Scanner(;
 String input = in.nextLine();
 if(testPangram(input)) {
 } else {
 System.out.println("not pangram");

 static boolean testPangram(String input) {
 for(char a = 'A' ; a <= 'Z' ; a++) {
 if(input.indexOf(a) < 0 && input.indexOf((char) a+32) < 0) {
 return false;
 return true;

Result for input “We promptly judged antique ivory buckles for the prize “:





Categories: JAVA Tags: , ,

Is Fibo


You are given an integer, N. Write a program to determine if N is an element of the Fibonacci Sequence.

Solution I choose is using this formula:

fibocheck or fibocheck2


Then check if the result is a perfect square.

Java code:

public class IsFibo {

public static void main(String[] args) {
Scanner in = new Scanner(;
int a = in.nextInt();
long[] arrays = new long[a];
for(int i=0; i < a; i++) {
arrays[i] = in.nextLong();
for(int i=0; i < arrays.length; i++) {

private static String isFibo(long suspectFibo) {
if((Math.sqrt(5 * Math.pow(suspectFibo, 2) + 4)%1 == 0)
|| (Math.sqrt(5 * Math.pow(suspectFibo, 2) - 4)%1 == 0)) {
return "IsFibo";
return "IsNotFibo";

Result for 3 input (5, 7, 8):