Tuesday, November 27, 2012

Ubuntu 12.04 – install sun jdk 6-7


Ubuntu GNU/Linux 12.04 LTS (Precise Pangolin) released. I wanted to manually install the Sun JDK 6 and 7 on Ubuntu.
Installing Sun JDK 6 on Ubuntu 12.04:
  • Make the bin file executeable:
chmod +x jdk-6u32-linux-x64.bin
  • Extract the bin file:
./jdk-6u32-linux-x64.bin
  • Move extracted folder to this location:
sudo mv jdk1.6.0_32 /usr/lib/jvm/
  • Install new java source in system:
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_32/bin/javac 1
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_32/bin/java 1
sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_32/bin/javaws 1
  • Choose default java:
sudo update-alternatives --config javac
sudo update-alternatives --config java
sudo update-alternatives --config javaws
  • java version test:
java -version
  • Verify the symlinks all point to the new java location:
ls -la /etc/alternatives/java*
  • Enable Java plugin for Mozilla Firefox (even for Chrome)
#for 64-Bit jdk
sudo ln -s /usr/lib/jvm/jdk1.6.0_32/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins
#for 32-Bit jdk
sudo ln -s /usr/lib/jvm/jdk1.6.0_32/jre/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins
Installing Sun JDK 7 on Ubuntu 12.04:
  • Download the sun jdk 7 tar file from here
  • Extract the tar file:
tar -xvzf jdk-7u4-linux-x64.tar.gz
  • Move extracted folder to this location:
sudo mv jdk1.7.0_04 /usr/lib/jvm/
  • Install new java source in system:
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_04/bin/javac 1
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_04/bin/java 1
sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.7.0_04/bin/javaws 1
  • Choose default java:
sudo update-alternatives --config javac
sudo update-alternatives --config java
sudo update-alternatives --config javaws
  • java version test:
java -version
  • Verify the symlinks all point to the new java location:
ls -la /etc/alternatives/java*
  • Enable Java plugin for Mozilla Firefox (even for Chrome)
#for 64-Bit jdk
sudo ln -s /usr/lib/jvm/jdk1.7.0_04/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins
#for 32-Bit jdk
sudo ln -s /usr/lib/jvm/jdk1.7.0_04/jre/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins
Update: I have added Java Web Start configuration (Thanks Jack).
Update: I have added Java Plugin configuration for Mozilla Firefox even for Chrome (Thanks shetty).
Update: JAVA_HOME configuration: Some tools require JAVA_HOME variable. You can set JAVA_HOME in Ubuntu so simple: Edit the file .bashrc under your home directory and add the following lines: (if .bashrc is hidden click in Nautilus Menu View > Show Hidden Files)
export JAVA_HOME=/path/your/jdk
export PATH=$JAVA_HOME/bin:$PATH

Friday, November 16, 2012

Upgrade subversion from 1.6 to 1.7 on ubuntu 12.04


execute the following commands:

echo "deb http://opensource.wandisco.com/ubuntu lucid svn17" | sudo tee /etc/apt/sources.list.d/svn.list
sudo wget -q http://opensource.wandisco.com/wandisco-debian.gpg -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get dist-upgrade

Friday, October 12, 2012

Linux : search and replace string in a directory recursively

find /home/zana/folder -type f -exec sed -i 's/oldstring/newstring/g' {} \;


find . -type f -print0 | xargs -0 sed -i 's/Application/whatever/g'

Thursday, September 27, 2012

find and replace a file by another file recursively in all subdirectories

find . -type f -name "image.png" -printf "%h\n" | xargs -i cp /home/zana/DEVELOPMENT/LIB/DIR/Images/image.png "{}"'/'

Thursday, August 9, 2012

How to remove MySQL completely with config and library files on ubuntu 12.04



sudo apt-get remove mysql-server mysql-client mysql-common
sudo apt-get purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
shell>> locate mysql

Wednesday, June 13, 2012

The sky's the limit.


At Intel, we're unlocking the potential of the cloud. We envision a world where data and services are shared securely—confidently—from person to person across multiple clouds. Where shared resources and cloud infrastructure can be redeployed and reallocated on the fly. Where clouds are client aware, so people who access the cloud have a great experience no matter what device they're using. Intel®Architecture is ideal for the cloud, whether at the system, storage or network level.

The sky really is the limit. Here's how we're making it happen.

Intel® Cloud Builders Guide: Data Center Infrastructure and Energy Management with 3D visualization with Visual Data CenterBuilt on the Intel® Xeon® Processor E5-2600 Product Family

Intel® Cloud Builders Guide: Data Center Infrastructure and Energy Management with 3D visualization with Visual Data CenterBuilt on the Intel® Xeon® Processor E5-2600 Product Family

Intel® Cloud Builders Guide: Apache* Hadoop*

Intel® Cloud Builders Guide: Apache* Hadoop*

Wednesday, March 28, 2012

Set ulimit parameters on ubuntu


Set ulimit parameters on ubuntu

By default the number of open files  pro user in Ubuntu 8.04   is 1024. In my case this number was  too small so I have to increase it.This is done with the  ulimit command:
$ulimit -a   # see all the kernel parameters
$ulimit -n   #see the number of open files
$ulimit -n 9000  #  set the number open files to 9000
The problem with this way is that the ulimit parameter is only set currently  for this command terminla and user.If you open a new tab and type again ulimit -a you will see that the number of open files is 1024.This means that after a reboot you’ll need to set the parameter again.
First, in order to set this options automatically  you have to edit theetc/security/limits.conf file.
$sudo gedit /etc/security/limits.conf    #open the file in gedit
The # means that this part is commented.The wildcard * means  for all users.We need to set the nofile option meaning maximum number of open files.If you want to change the number of files of user, you should add this line in the limits.conf:
user  soft  nofile 9000
user  hard  nofile 65000
If  you want to set the nofile only for superuser you just write root instead of user.
root soft  nofile 9000
root hard  nofile 65000
Second you have to add a line in the /etc/pam.d/common-session file:
$ sudo gedit /etc/pam.d/common-session #open the file in gedit
Then add the line:
session required pam_limits.so
Now after rebooting you can see in the terminal with ulimit -a the change.
The option with wildcard *didn’t work for me , because I used root accout to run my programms and wildcard option doesn’t affect the superuser.
Remark: Using the same steps you should be able to set and change other parameters ( core file size, max user processes, stack size ….) from the ulimit options.
References:

Saturday, March 17, 2012

Android Connect to FTP server example


Connect to FTP server example

This is the android coding example showing how to connect to FTP server and some basic file operations such as downloading, uploading, deleting, renaming file, and creating new directory.
You must import the following FTP client library, download it here:
import org.apache.commons.net.ftp.*;

Now, declare a public FTP client object.
public FTPClient mFTPClient = null;

Method to connect to FTP server:
public boolean ftpConnect(String host, String username,
                          String password, int port)
{
    try {
        mFTPClient = new FTPClient();
        // connecting to the host
        mFTPClient.connect(host, port);

        // now check the reply code, if positive mean connection success
        if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
            // login using username & password
            boolean status = mFTPClient.login(username, password);

            /* Set File Transfer Mode
             *
             * To avoid corruption issue you must specified a correct
             * transfer mode, such as ASCII_FILE_TYPE, BINARY_FILE_TYPE,
             * EBCDIC_FILE_TYPE .etc. Here, I use BINARY_FILE_TYPE
             * for transferring text, image, and compressed files.
             */
            mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
            mFTPClient.enterLocalPassiveMode();

            return status;
        }
    } catch(Exception e) {
        Log.d(TAG, "Error: could not connect to host " + host );
    }

    return false;
}

Method to disconnect from FTP server:
public boolean ftpDisconnect()
{
    try {
        mFTPClient.logout();
        mFTPClient.disconnect();
        return true;
    } catch (Exception e) {
        Log.d(TAG, "Error occurred while disconnecting from ftp server.");
    }

    return false;
}

Method to get current working directory:
public String ftpGetCurrentWorkingDirectory()
{
    try {
        String workingDir = mFTPClient.printWorkingDirectory();
        return workingDir;
    } catch(Exception e) {
        Log.d(TAG, "Error: could not get current working directory.");
    }

    return null;
}

Method to change working directory:
public boolean ftpChangeDirectory(String directory_path)
{
    try {
        mFTPClient.changeWorkingDirectory(directory_path);
    } catch(Exception e) {
        Log.d(TAG, "Error: could not change directory to " + directory_path);
    }

    return false;
}

Method to list all files in a directory:
public void ftpPrintFilesList(String dir_path)
{
    try {
        FTPFile[] ftpFiles = mFTPClient.listFiles(dir_path);
        int length = ftpFiles.length;

        for (int i = 0; i < length; i++) {
            String name = ftpFiles[i].getName();
            boolean isFile = ftpFiles[i].isFile();

            if (isFile) {
                Log.i(TAG, "File : " + name);
            }
            else {
                Log.i(TAG, "Directory : " + name);
            }
        }
    } catch(Exception e) {
        e.printStackTrace();
    }
}

Method to create new directory:
public boolean ftpMakeDirectory(String new_dir_path)
{
    try {
        boolean status = mFTPClient.makeDirectory(new_dir_path);
        return status;
    } catch(Exception e) {
        Log.d(TAG, "Error: could not create new directory named " + new_dir_path);
    }

 return false;
}

Method to delete/remove a directory:
public boolean ftpRemoveDirectory(String dir_path)
{
    try {
        boolean status = mFTPClient.removeDirectory(dir_path);
        return status;
    } catch(Exception e) {
        Log.d(TAG, "Error: could not remove directory named " + dir_path);
    }

    return false;
}

Method to delete a file:
public boolean ftpRemoveFile(String filePath)
{
    try {
        boolean status = mFTPClient.deleteFile(filePath);
        return status;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}

Method to rename a file:
public boolean ftpRenameFile(String from, String to)
{
    try {
        boolean status = mFTPClient.rename(from, to);
        return status;
    } catch (Exception e) {
        Log.d(TAG, "Could not rename file: " + from + " to: " + to);
    }

    return false;
}

Method to download a file from FTP server:
/**
 * mFTPClient: FTP client connection object (see FTP connection example)
 * srcFilePath: path to the source file in FTP server
 * desFilePath: path to the destination file to be saved in sdcard
 */
public boolean ftpDownload(String srcFilePath, String desFilePath)
{
    boolean status = false;
    try {
        FileOutputStream desFileStream = new FileOutputStream(desFilePath);;
        status = mFTPClient.retrieveFile(srcFilePath, desFileStream);
        desFileStream.close();

        return status;
    } catch (Exception e) {
        Log.d(TAG, "download failed");
    }

    return status;
}

Method to upload a file to FTP server:
/**
 * mFTPClient: FTP client connection object (see FTP connection example)
 * srcFilePath: source file path in sdcard
 * desFileName: file name to be stored in FTP server
 * desDirectory: directory path where the file should be upload to
 */
public boolean ftpUpload(String srcFilePath, String desFileName,
                         String desDirectory)
{
    boolean status = false;
    try {
        FileInputStream srcFileStream = new FileInputStream(srcFilePath);

        // change working directory to the destination directory
        if (ftpChangeDirectory(desDirectory)) {
            status = mFTPClient.storeFile(desFileName, srcFileStream);
        }

        srcFileStream.close();
        return status;
    } catch (Exception e) {
        Log.d(TAG, "upload failed");
    }

    return status;
}

Friday, February 24, 2012

Dynamic Web Service Client

In Apache Axis2, the are several ways to write a client for a web service. One approach would be to use WSDL2Java, the code generation tool provided with Axis2 generate a stub for the web service and use that stub to consume the web service. Other option is to write a dynamic client. This is how you can write a dynamic client for a web service.

We will you expose a simple POJO as a web service.

  1. package org.wso2.training;  
  2.   
  3. public class CalculatorService {  
  4.     
  5.    public int add (int a, int b) {  
  6.        return a + b;  
  7.    }  
  8.     
  9.    public int multiply(int a, int b) {  
  10.        return a * b;  
  11.    }  
  12.     
  13. }  
Exposing this as a web service is a matter of 2 lines of code ...
  1. AxisServer axisServer = new AxisServer();  
  2. axisServer.deployService(CalculatorService.class.getName());  
Now, the WSDL for this web service will be available at
  1. http://localhost:6060/axis2/services/CalculatorService?wsdl  
Now let's see how we can write a dynamic client for this web service
  1.         //Create a service client for given WSDL service by passing the following four parameters  
  2.         //ConfigurationContext - we keep it as null  
  3.         //wsdlURL - The URL of the WSDL document to read  
  4.         //wsdlServiceName The QName of the WSDL service in the WSDL document   
  5.         //portName        The name of the WSDL 1.1 port to create a client for.   
  6.           
  7.         RPCServiceClient dynamicClient = new RPCServiceClient(nullnew URL(  
  8.                 "http://localhost:6060/axis2/services/CalculatorService?wsdl"), new QName(  
  9.                 "http://training.wso2.org""CalculatorService"),  
  10.                 "CalculatorServiceHttpSoap12Endpoint");  
  11.   
  12.         // We provide the parameters as an object array and return types as an class array  
  13.         Object[] returnArray = dynamicClient.invokeBlocking(new QName("http://training.wso2.org","add"),  
  14.                 new Object[] { 12 }, new Class[] { Integer.class });  
  15.           
  16.         System.out.println("1 + 2 = " + returnArray[0]);  
  17.           
  18.         returnArray = dynamicClient.invokeBlocking(new QName("http://training.wso2.org","multiply"),  
  19.                 new Object[] { 12 }, new Class[] { Integer.class });  
  20.           
  21.         System.out.println("1 X 2 = " + returnArray[0]);  
  22.   
  23. .