Category Archives: Java EE

Java Entreprise Edition Programming

Get External/Local Ip regardless to Network Device in Linux

#!/bin/bash
# Date:     January 2015
# Author:  Hanine HAMZIOUI
# Usage:    Get the Machine IP. Commands are fallbacks
#           Just do: $~ bash ip.sh or bash.sh local/private/host
 
COM1=$(dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null)
COM2=$(hostname -i 2>/dev/null)
COM3=$(ip route show 2>/dev/null | grep src | grep -vE 'eth1.*|lo' |  awk -Fsrc '{print $2}' | sed -e 's/ //g')
COM4=$(curl -s monip.org 2>/dev/null | grep -o -E '([0-9]+\.){3}[0-9]+')
COM5=$(host `hostname -f 2>/dev/null` | awk -F[aA]ddress '{print $2}' | sed 's/ //g')
COM6=$(for i in eth0 em1 bond0; do inf=`ip -4 addr show dev $i 2>/dev/null | grep inet -m1 | cut -d/ -f1 | awk '{ print $2}'`;if [[ "$inf" =~ [0-9][0-9]?* ]]; then echo "$inf";fi ;done)
if [[ "$1" =~ local ]] ;then
    COM1=$COM3
fi
if [[ "$1" =~ private ]] ;then
    COM1=$COM2
fi
if [[ "$1" =~ host ]] ;then
    COM1=$COM5
fi
IP=''
validip()
{
    local  ip=$1
    local  stat=1
 
    if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
        OIFS=$IFS
        IFS='.'
        ip=($ip)
        IFS=$OIFS
        [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
        stat=$?
    fi  
    if [ "$stat" -eq 0 ]; then
        echo $IP
    else
        echo $stat
    fi  
    return $stat
}
if [ -n "${COM1}" ];then
    IP=${COM1}
    eval validip $IP
    exit
fi
 
if [ -n "${COM2}" ];then
    IP=${COM2}
    eval validip $IP
    exit
fi
if [ -n "${COM3}" ];then
    IP=${COM3}
    eval validip $IP
    exit
fi
if [ -n "${COM4}" ];then
    IP=${COM4}
    eval validip $IP
    exit
fi
 
if [ -n "${COM5}" ];then
    IP=${COM5}
    eval validip $IP
    exit
fi
if [ -n "${COM6}" ];then
    IP=${COM6}
    eval validip $IP
    exit
fi
exit
Advertisements

Beautify LibreOffice with a new set of Chrome Icons

The era of very ugly LibreOffice icons is over. A new set of beautiful and homogeneous icons is being prepared for the next versions of LibreOffice.

libreoffice_icons

libreoffice_Icons

You can use the Beta version if you’re impatient like me. This is how:

Copy/Paste the content of this script below in a text file in your Desktop folder (name it for example: icoffice.sh, and give it execution permissions:

#!/bin/bash
# Script that downloads Libreoffice new gnome icons
# Author: hanynowsky 2013
# After executing this script: From the LibreOffice menu select Tools > Options,
# then under LibreOffice > View > Icon size and style, set the icon theme to "Crystal"
sudo apt-get install libreoffice-style-crystal
cd /tmp && wget https://github.com/hotice/myfiles/raw/master/images_flat.zip

if [ -d "/usr/share/libreoffice/share/config/" ]; then
sudo cp images_flat.zip /usr/share/libreoffice/share/config/images_crystal.zip
else echo "No official LibreoFfice?"
fi

if [ -d "/opt/libreoffice4.0/share/config/" ]; then
sudo cp images_flat.zip /opt/libreoffice4.0/share/config/images_crystal.zip
else echo "No custom Libreoffice - it is okay!"
fi
exit 0

and then

chmod +x ~/Desktop/icoffice.sh

And finally:

bash ~/Desktop/icoffice.sh

You’ll be prompted to type your password in order to achieve installation of the new icon set.
Once finished, after executing this script: From the LibreOffice menu select Tools -> Options. Then under LibreOffice -> View -> Icon size and style, set the icon theme to “Crystal

Ubuntu 13.10 Saucy on Dell XPS L502X

This post mentions some issues and fixes after upgrading to Ubuntu 13.10.

For Ubuntu 13.04 and previous versions, please refer to the corresponding post.

Nvidia Optimus:

– First of all, once the upgrade has completed, the user should workaround bumblebee to make it work:

When you run optirun command, you get an error message like this:

error while loading shared libraries: libturbojpeg.so: cannot open shared object file: No such file or directory

Open a Terminal and type:

sudo ln -s /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0 /usr/lib/x86_64-linux-gnu/libturbojpeg.so

and

sudo ln -s /usr/lib/i386-linux-gnu/libturbojpeg.so.0 /usr/lib/i386-linux-gnu/libturbojpeg.so

—————————————————-

SD Card Reader:

Up to 13.04, the SD card reader was not really functional, unless you boot up with the card inserted. This bug has been fixed in Kernel 3.12 and should be backported soon to 13.10. Patience.

We’d be updating this post by this week-end, with useful information.

HoneyBee Portal For Naturopathy. A Java EE Cloud Application

HoneyBee Portal for Naturopathy

A Starting version of a new open source Java EE web portal has come to life, thanks to PaaS offering from Red Hat. The application is pure Java EE work, running the following environment:
  • View Framework: JavaServer Faces (JSF) as View Framework 2.1.
  • Database: Oracle MySQL 5.5.
  • Application Container: JBoss AS 7.1.1
  • JSF Facelets Library: PrimeFaces 3.5 & PrimeFaces Mobile 0.9.
  • Compatible Browsers: Mozilla Firefox +3 & Google Chrome. (No Internet Explorer).
  • Build Automation System: Maven 3
  • Persistence Provider: JPA through Hibernate 4.
  • Business Layer: EJB 3 & Faces Managed Beans.
  • Testing framework: Arquillian through JUnit
  • Code Source Host: GitHub
  • Operating System: Ubuntu Linux 13.04.
  • Cloud Host: Paas OpenShift
HoneyBee
This application was designed with love and passion. It’s multiligual and should let the user interact with a database of Naturopathy. The common user can browse natural prescriptions, plants.. Using human body parts, cure virtues, types of illnesses or defects, computes his/her body mass index and determine somatotype ….
People interested in contributing either technically or functionally to the application are welcome. Nevertheless, content is being filled continuously, and updates are not regular, so please do not expect to find almost everything related to Naturopathy. If you have time to contribute, please feel free to contact us.

Oracle Sun JDK 7 : Derby Server (Java DB) does not start using Glassfish 3.1.2 in Netbeans 7.1.2: Permission denied

Apache Derby

Apache Derby

Assuming you’re using JDK 7 in Linux (Here Ubuntu 12.04 LTS), when deploying a web application on Glassfish 3.1.2 using Netbeans 7.1.2, Derby might likely not start and get ready to receive connections, and this due to an exception thrown (JDK 7 security).
which is:

Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "file.encoding" "read")

You can for now append this permission below to the java policy file that is shipped with JDK 1.7.:
permission java.util.PropertyPermission "file.encoding", "read";

The file should like this:

// Standard extensions get all permissions by default

grant codeBase "file:${{java.ext.dirs}}/*" {
permission java.security.AllPermission;
};

// default permissions granted to all domains

grant {
// Allows any thread to stop itself using the java.lang.Thread.stop()
// method that takes no argument.
// Note that this permission is granted by default only to remain
// backwards compatible.
// It is strongly recommended that you either remove this permission
// from this policy file or further restrict it to code sources
// that you specify, because Thread.stop() is potentially unsafe.
// See the API specification of java.lang.Thread.stop() for more
// information.
permission java.lang.RuntimePermission "stopThread";

// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "localhost:1024-", "listen";

// "standard" properies that can be read by anyone

permission java.util.PropertyPermission "java.version", "read";
permission java.util.PropertyPermission "java.vendor", "read";
permission java.util.PropertyPermission "java.vendor.url", "read";
permission java.util.PropertyPermission "java.class.version", "read";
permission java.util.PropertyPermission "os.name", "read";
permission java.util.PropertyPermission "os.version", "read";
permission java.util.PropertyPermission "os.arch", "read";
permission java.util.PropertyPermission "file.separator", "read";
permission java.util.PropertyPermission "path.separator", "read";
permission java.util.PropertyPermission "line.separator", "read";

permission java.util.PropertyPermission "java.specification.version", "read";
permission java.util.PropertyPermission "java.specification.vendor", "read";
permission java.util.PropertyPermission "java.specification.name", "read";

permission java.util.PropertyPermission "java.vm.specification.version", "read";
permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
permission java.util.PropertyPermission "java.vm.specification.name", "read";
permission java.util.PropertyPermission "java.vm.version", "read";
permission java.util.PropertyPermission "java.vm.vendor", "read";
permission java.util.PropertyPermission "java.vm.name", "read";
permission java.util.PropertyPermission "file.encoding", "read";
};

N.B: The file is found here in our case /usr/lib/jvm/jdk1.7.0/jre/lib/security/java.policy

More info: http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.base.doc%2Finfo%2Faes%2Fae%2Frsec_javapolicy.html

Adoption of Java Web Frameworks & Library Components Statistics

A recent study bu OIO Compass (April 2012) provides the following:

jsf 2.0

Duke with JSF 2

The selected web frameworks

Caveat: The study participants have indicated a 73% interest with the selection of the framework to be satisfied.

The spectrum of the finally chosen web framework is set up pretty wide. The most common decision was taken in connection with the JSF specification, a total of 32% of participants chose JSF.

Employed Web Framework

Figure: Employed Web Framework

In second place come Spring MVC and GWT with 16%.

The evidence today than market rates prestigious web frameworks in the Java environment JSF, Spring MVC and GWT 62% of the decisions. Grails, Groovy-based framework is one, with 16% in the 4th Place, although the developers have to learn a new language (Groovy).

Interestingly enough, with Spring MVC and 32% of the Grails framework used in the home SpringSource and VMware.

The fragmentation in the Java web framework environment is even more apparent when the are usually brought in connection with JSF components used in libraries.

Much as 35% of participants who have opted for the use of JSF have also decided to develop their own UI components.

JSF component libraries

Figure: JSF component libraries

Source: http://www.oio.de/public/java/java-web-frameworks-vergleich/jsf-vs-gwt-studie.htm#a13