Latest commit e5c4e9d Jan 19, 2017 @tensorflower-gardener tensorflower-gardener committed with tensorflower-gardener Add @Ignore instead of commenting out @Test for tests that need
to be disabled.
Change: 144924509

TensorFlow for Java

Java bindings for TensorFlow.

WARNING: The TensorFlow Java API is incomplete and experimental and can change without notice. Progress can be followed in issue #5.

Till then, for using TensorFlow on Android refer to contrib/android, makefile and/or the Android camera demo.


  • bazel
  • Environment to build TensorFlow from source code (Linux or Mac OS X). If you'd like to skip reading those details and do not care about GPU support, try the following:

    # On Linux
    sudo apt-get install python swig python-numpy
    # On Mac OS X with homebrew
    brew install swig


Build the Java Archive (JAR) and native library:

bazel build -c opt \
  //tensorflow/java:tensorflow \


To use the library in an external Java project, publish the library to a Maven repository. For example, publish the library to the local Maven repository using the mvn tool (installed separately):

bazel build -c opt //tensorflow/java:pom
mvn install:install-file \
  -Dfile=../../bazel-bin/tensorflow/java/libtensorflow.jar \

Refer to the library using Maven coordinates. For example, if you're using Maven then place this dependency into your pom.xml file (replacing 0.12.head with the version of the TensorFlow runtime you wish to use).



With bazel

Add a dependency on //tensorflow/java:tensorflow to the java_binary or java_library rule. For example:

bazel run -c opt //tensorflow/java/src/main/java/org/tensorflow/examples:label_image

With javac

  • Add libtensorflow.jar to classpath for compilation. For example:

    javac \
      -cp ../../bazel-bin/tensorflow/java/libtensorflow.jar \
  • Make libtensorflow.jar and (libtensorflow_jni.dylib on OS X) available during execution. For example:

    java \
      -Djava.library.path=../../bazel-bin/tensorflow/java \
      -cp ../../bazel-bin/tensorflow/java/libtensorflow.jar:./src/main/java \