How to Install JPCap on Linux
In this tutorial I will describe how to install JPCap from source code on Linux (Ubunty 7.10 or Debian 4.0).
JPCap is an open-source Java library released under the GNU LGPL and designed to enable the capturing and sending network packets in Java. JPCap is developed by Keita Fujii and the University of California and Irvine.
The JPCap home page is http://netresearch.ics.uci.edu/kfujii/jpcap/doc/
JPCap is a Java Native Library Implementation (JNI) of the popular libpcap library and should therefor work on any OS which supports libpcap. libpcap is a user-level packet capture library that provides a common, system-independent API for low-level network monitoring. libpcap is also open-source software developed and maintained by TCPDump.org.
We will use JPCap and libpcap on the Linux operating system but the both libraries work on Microsoft Windows (WinPcap), Linux, FreeBSD, and Mac OS X.
JPCap supports the following types of network data:
Layer 2:Â Â Â Ethernet Datagrams
Layer 3:Â Â Â IPv4 & Ipv6 Â Â Â ARP/RARP
TCP, UDP and ICMPv4.
JPCap recognizes the packet types enumerated above but can capture any type of network traffic as a raw packet (i.e., as an instance of the Packet class) which contains the Packet’s whole data. This feature allows Java applications to analyze any packet type.
Step 1:Â Â Â Preparing the System
Following are instructions to install JPCap on a fresh installation of Ubuntu 7.10 of Debian 4.0.
Install the necessary development software packages to create a usable development environment:
Install the GNU compiler and basic libraries
% sudo apt-get install build-essential
Install the linux pcap library
% sudo apt-get install libpcap0.8
Install the Java SDK from Sun
% sudo apt-get install sun-java6-sdk
Download the latest JPCap source and extract it into your working directory
http://netresearch.ics.uci.edu/kfujii/jpcap/
You can also find version 0.7 here: JPCap 0.7
Step 2:Â Â Â Building & Installing the JPCap JNI library
In a terminal window, navigate to the [jpcap]/src/c directory. For example:
~/jpcap-0.7/src/c
[IMPORTANT] Edit the JAVA_DIR Makefile entry to point to your version of jni.h
You can find it quickly with the following command:
$ find /usr -name jni.h
/usr/lib/jvm/java-6-sun-1.6.0.03/include/jni.h
The Makefile should then read
JAVA_DIR = /usr/lib/jvm/java-6-sun-1.6.0.03
In the terminal window under the [jpcap]/src/c directory type make to create the shared library
$ make
This will create the file ‘libjpcap.so’.
Copy ‘libjpcap.so’ your system’s Java JNI library directory
‘[Java-dir]/jre/lib/<arch>’ where <arch> is either ‘i386′ or ‘sparc’.
For my installation, this was /usr/lib/jvm/java-6-sun/jre/lib/i386
Another option is to copy the library to the directory where your application is located.
Step 3:Â Â Â Building and Installing the JPCap JAR file
In a terminal window, nagivate to the [jpcap]/src/java directory. For example:
~/jpcap-0.7/src/java
There should be one subdirectory named ‘jpcap’
Compile all of the .java files in the ‘jpcap’ and ‘jpcap/packet’ directories.
$ find . -name “*.java” -exec javac {} \;
You may see the following error for IPPacket.java – ignore it.
“Note: ./jpcap/packet/IPPacket.java uses unchecked or unsafe operations.”
Create the JAR file
jar -cf jpcap.jar jpcap
Confirm the contents of your JAR file with the following command:
jar -tvf jpcap.jar
Copy the new jpcap.jar file to your Java extentions directory
$ cp jpcap.jar ‘[Java-dir]/jre/lib/ext/
For my installation, this was /usr/lib/jvm/java-6-sun/jre/lib/ext
Another option is to copy the JAR file to your application’s directory and add it to your CLASSPATH.
You are now ready to begin using the JPCAP Java Native Interface Library.

One annoyance about OSX is that is leaves behind a .DS_Store file on network share drives (Samba, etc.) This file contains folder-specific display preferences for the way those files and folders should be viewed.