码迷,mamicode.com
首页 > 其他好文 > 详细

Debian环境下的Jpcap 安装与配置

时间:2015-03-16 16:18:28      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

环境:Debian3.2.60-1+deb7u1 x86_64 GNU/Linux

工具包:

    jdk-6u45-linux-x64.bin 

    libpcap-1.6.1.tar.gz  (下载地址:http://www.tcpdump.org/#latest-release)

    jpcap-0.7.tar.gz

 

安装过程:

1.      安装JDK (此处安装的为JDK1.6),并配置环境。

2.      安装下面软件之前,最好升级更新一下,以免有缺失软件包的错误

    $ apt-get update

前提软件包括:gcc、flex、make 、bison

逐个检测是否存在,不存在则安装

    $apt-get install gcc

    $ apt-get install flex

    $ apt-get install make

    $ apt-get install bison

3.      将libpcap-1.6.1.tar.gz解压后复制到/usr/lib/jvm/下[具体目录按各系统情况自定]

  $tar zxvf libpcap-1.6.1.tar.gz

  $tar libpcap-1.6.1 /usr/lib/jvm/

         然后进入该目录下:/usr/lib/jvm/libpcap-1.6.1

         运行命令:

      $./configure  –回车

      $make  –回车

      $make install –回车

        

         [注意]:将/usr/local/lib下的libpcap.so.1

复制到/usr/lib/jvm/j2sdk1.6oracle/jre/lib/amd64/下,

否则最后编译文件后,运行会提醒找不到libpcap.so.1,(编译后进行链接亦可)

  $cp libpcap.so.1 /usr/lib/jvm/j2sdk1.6oracle/jre/lib/amd64/

 

4.      将jpcap-0.7.tar.gz解压后复制到/usr/lib/jvm/下[具体目录视安装情况而定]

  $tar zxvf jpcap-0.7.tar.gz

  $cp jpcap-0.7 /usr/lib/jvm/

然后进入到jpcap安装目录src/c中,打开Makefile文件找到:

  $(CC) $(COMPILE_OPTION) -I$(JNI_INCLUDE) 这一行修改为

  $(CC) $(COMPILE_OPTION) -fPIC -I$(JNI_INCLUDE)  并保存

然后在src/c目录中输入命令

  $ make –回车

这时会在src/c目录生成libjpcap.so文件,

注:如果libjpcap.so文件没有生成的话,请检查以上所提软件包有没有全部安装。

最后把生成的libjpcap.so,复制到你java目录/jre/lib/amd64下。

并将jpcap解压目录/lib下的jpcap.jar,复制到你java目录/jre/lib/ext

    $cp libpcap.so /usr/lib/jvm/j2sdk1.6oracle/jre/lib/amd64/

    $cp jpcap.jar   /usr/lib/jvm/j2sdk1.6oracle/jre/lib/ext

 

最后附上Shell Script文件,可以一键安装Jpcap和JDK,

 

#! /bin/bash
#! /bin/bash
#
# Program:
#    Usage: InstallJacap <source files> <source files> [<source files>]
#
#    This program can help you install Jacap rapidly
#    and help configure relevant settings.
#    
# History:
# 2014/7/31   Li Yunpeng  First release

function GetFilename(){
    ls > /tmp/InstallJavaCatalog.old
    #Decompressing files
    #echo "start to tar..."
    if  # Different packages use different way to unzip
      echo $1 | sed s/^.*\.//g| grep "gz"
    then
          tar zxvf "$1"
    else
        ./$1
    fi
    ls> /tmp/InstallJavaCatalog.new
    #Get the folders name of Java
    diff /tmp/InstallJavaCatalog.old /tmp/InstallJavaCatalog.new | grep "^>" |tr -d > 
    #Delete temporary files
    rm -f /tmp/InstallJavaCatalog.old
    rm -f /tmp/InstallJavaCatalog.new
}

function InstallJDK() {
    echo "start to install Java..."
    JavaFilename=`GetFilename "$1"`
       
    #Found the folder
    #Move Javas folder to /usr/lib/jvm/
    mv -i $JavaFilename /usr/lib/jvm/
    echo "complete the installation of Java..."
    echo "configuring relevant settings about Java..."
    #Add the environment variable
    echo  "JAVA_HOME=/usr/lib/jvm/$JavaFilename" >> /etc/profile
    echo  PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH >> /etc/profile
    source /etc/profile
} #Install JDK


#check up if log in by root
if [ `whoami` != "root" ];then
    echo "Please use this command in root."
    exit 1
fi

InstallCatalog=`pwd`
mkdir -p /usr/lib/jvm/

case $# in
  "2")
    #Exclude other documents.
    if 
      [[ $(echo $1 | sed s/^.*\.//g | grep "gz" > /dev/null) &&       $(echo $2 | sed s/^.*\.//g | grep "gz" > /dev/null) ]]
    then
        echo "File type error ."
        echo "InstallJacap <*.tar.gz> <*.tar.gz> ."
    fi
    #Check if Java has been installed
    if
           ! echo $JAVA_HOME > /dev/null
        then
        echo "Java has NOT been installed."
        exit 1
    fi
    ;;
  "3")
    #Exclude other documents.
    if
     [[ $(echo $1 | sed s/^.*\.//g| grep -E bin|gz > /dev/null) &&         $(echo $2 | sed s/^.*\.//g| grep "gz"  > /dev/null) &&         $(echo $3 | sed s/^.*\.//g| grep "gz" > /dev/null) ]]
    then  
      echo "File type error ."
      echo "InstallJacap <*.bin> <*.tar.gz> <*.tar.gz> ."
    fi
    #Check if Java has been installed
    if 
      echo $JAVA_HOME > /dev/null
    then
        #Install Java
        InstallJDK $1
        shift
    else
        
        echo "Java has been already installed."
        exit 1
    fi
    ;;
    
  *)
    echo "parameter(s) error."
    exit 1
    ;;
esac

#First determine the catalog ,Because different Javas versions can lead to configuration files which will move to different folder.
cd ${JAVA_HOME}/jre/lib
if [ -e amd64 ];then
    Moveto=amd64
else
    Moveto=i586
fi
Catalog=${JAVA_HOME}/jre/lib/${Moveto}
cd $InstallCatalog

source /etc/profile
#check gcc,flex,make and bison exist
echo "Check gcc,flex,make and bison exist"
dpkg -l | grep gcc  > /dev/null || apt-get install gcc
dpkg -l | grep flex > /dev/null || apt-get install flex
dpkg -l | grep make > /dev/null || apt-get install make
dpkg -l | grep bison > /dev/null || apt-get install bison

LibpcapFilename=$(GetFilename "$1")
#move folder
mv -i $LibpcapFilename /usr/lib/jvm/
cd /usr/lib/jvm/$LibpcapFilename
./configure
make
make install
cp /usr/local/lib/libpcap.so.1 $Catalog


cd $InstallCatalog
JpcapFilename=$(GetFilename "$2")
#move folder
mv -i $JpcapFilename /usr/lib/jvm/
#add "-fPIC" to "Makefile"
sed -i s/$(CC) $(COMPILE_OPTION)/$(CC) $(COMPILE_OPTION) -fPIC/g /usr/lib/jvm/$JpcapFilename/src/c/Makefile
cd /usr/lib/jvm/$JpcapFilename/src/c
make
#move libjpcap.so to $Catalog  ps:$Catalog=${JAVA_HOME}/jre/lib/[amd64 or i386 or i686]
cp libjpcap.so $Catalog

#move jpcap.jar to ${JAVA_HOME}/jre/lib/ext
cp /usr/lib/jvm/$JpcapFilename/lib/jpcap.jar ${JAVA_HOME}/jre/lib/ext


echo "--------------------------------------"
echo "Installation has been completed."
echo "Please logoff."
echo "--------------------------------------"

 

 

 

Debian环境下的Jpcap 安装与配置

标签:

原文地址:http://www.cnblogs.com/ypli/p/4341870.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!