jNetPcap is a java project that comes with a required native shared library. The requirement of a native library typically adds confusion and presents difficulty for many as to how properly setup a project in eclipse to reference jNetPcap library correctly.
There are several ways that jNetPcap can be added to your existing java project in Eclipse IDE. Let me briefly outline them here and then lets go through the detailed steps of actually creating a proper build path so your project will compile with jNetPcap.
We recommend approaches #1 and #2 for development. If you are creating a single jnetpcap dependent project, approach #2 may be all you need. On the other hand if you want to set it up once for many projects, approach #1 is what we recommend.
Setup #3 and #4 are not recommended for a build environment, and will not be discussed here.
First thing you have to do is download and install (or unzip) the jNetPcap installation package. You do not have to install (unzip or untar) the installation package under an Eclipse workspace, unless you want to for a specific. The installation can be external to the workspace. Since each jNetPcap installation package installs under a unique directory path, you can easily have multiple versions of the library and switch between them when needed. Both installable and extractable unix and windows packages are provided. Under unix the packager installed packages are intended for production environments, that have a jNetPcap requirement. At same time the JAR and unzip packages are provided incase you need multiple versions of the library where you can extract on your own and easily switch between them.
In the below examples we are going to assume that we extracted 2 versions of jnetpcap library under "c:\libs" directory (on a windows platform). For unix you can assume a home directory based path "$HOME/libs" or something similar. In the "libs" directory we installed version jnetpcap-1.2 and jnetpcap-1.3.b0010.
We are also going to assume that the user has extracted/installed all 3 packages of jnetpcap (the executable package), jnetpcap-javadoc, jnetpcap-src for both versions above.
Setting up a "user library" under eclipse IDE platform, is a way for you to define in one place a single or multiple java libraries along with all of their requirements such as "native libraries", javadoc documentation and where to do lookups for source code incase you want to drill down into a function. This is also a neat way to change versions of the library globally without having to modify build paths for each project you have setup.
To create a new "user library" under Elicpse is easy.
Window->preferences
either search "user" in dialog's search box
or
Java->Build Path->User Libraries
Click the "Add JARs..." button
Now that a "user library" has been setup, you can add this user library to any of your Eclipse projects that need jnetpcap. You add the "user library" to each project's "Build Path". To do that, here are the instructions:
Project->Properties->Java Build Path
or right click on the project in "Package Explorer" and select
Build Path->Configure Build Path
You can do this for all other java projects in your workspace that need jnetpcap library.
The benefit of using a "user library" is that you can easily change the version of jnetpcap the "user library" is referencing by modifying the paths for jar, native, javadoc and source locations in this one place. You may also create multiple "user libraries" that reference different versions of 'jnetpcap' user library. For example, you can setup a "jnetpcap-production" library that references a production version of jnetpcap and additional user libraries such as "jnetpcap-latest", "jnetpcap-1.3.b0010", etc. Then decide which of your own projects should be using which version of the library.
The source and javadocs will automatically be changed as well, making this a very robust development environment for your project.
Another approach is to add the jnetpcap.jar file (from directory c:\lib\jnetpcap-1.2 for example) to your project's build path. Once added you can still modify for that particular library where the required native library resides. This is a good approach if you only have a single java project that needs jnetpcap.
To add jnetpcap to your project's build path:
Project->Properties->Java Build Path
or right click on the project in "Package Explorer" and select
Build Path->Configure Build Path
Now jnetpcap library and its native library are added to your project. If you added javadoc and source locations, you can also see javadocs in Eclipse (hover or javadoc display) and drill down into jnetpcap methods and view their source.