This project is a Java API and JNA bindings for libgphoto2.  It allows Java applications to access cameras using the libgphoto2 library.  It is similar to the gphoto2-java project.  It has currently been tested on Ubuntu and Raspberry Pi and was developed as one part of a larger (proprietary) project.

Part of the motivation for building this library was to work around an issue in which the gphoto2 command-line interface stops responding when running on the Raspberry Pi.

How it Works

Java Native Access (JNA) lets Java make calls to native shared libraries.   libgphoto2-jna uses JNA bindings generated by jnaerator which have been modified and wrapped by an easy-to-use API.


To use libgphoto2-jna, you will need:

  • Linux – gphoto2 does not run on Windows (unless you build it under Cygwin but I haven’t tested it).
  • ghoto2 or at a minimum, from the gphoto2 project.
  • a camera supported by gphoto2
  • Java JDK with JNA support and probably some development environment like Netbeans or Eclipse
  • Apache Ant (if not part of your IDE)
  • a git client

If you are a Java developer, you most likely have all these tools installed already.  On Debian/Ubuntu/Raspbian you can install the the prerequisites and test your setup like this:

sudo apt-get install openjdk-7-jdk libjna-java git ant gphoto2 
sudo apt-get install libgphoto2-6   #some distros may use libgphoto2-2 instead
gphoto2 --capture-image-and-download

How to Build

Make sure you have all the prerequisites installed, then run the following:

git clone
cd libgphoto2-jna
ant #or open the project in netbeans IDE

The output, libgphoto2-jna.jar will be found in the “dist” directory and documentation can be found in “dist/javadoc”

How to Use

  1. Build the library (above), then add libgphoto2-jna.jar  to your Java project’s classpath.
  2. Make sure libgphoto2 is installed and that is in your library path.
  3. Read the API javadoc ( see dist/javadoc) and checkout the examples.

Here is an example showing how to take a pictures:

void example() throws IOException {
    GPhoto2 camera = new GPhoto2();;

Here is another example showing how to modify several camera settings and then take 5 shots using burst mode.

void setBurstMode() throws IOException {
    GPhoto2 camera = new GPhoto2();;

    GPhoto2Config config = new GPhoto2Config(camera);
    config.setParameter("burstnumber", "5");
    config.setParameter("capturetarget", "Memory card");



The most common cause of this error is trying to use libgphoto2-jna on Windows. is a Linux library,  which must be in your path.  Newer distros and packages may include or but not    There are two fixes:  edit GPhoto2.Java line 90 and change the name of the library, or create a symbolic link.  For example:

sudo ln -s /usr/lib/i386-linux-gnu/ /usr/lib/i386-linux-gnu/

Other Issues

Please use the issue tracker on GitHub to report any other problems.