aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/java/README.md
diff options
context:
space:
mode:
authorGravatar Asim Shankar <ashankar@google.com>2017-03-27 17:35:03 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-03-27 20:56:21 -0700
commitad93dc71f1154c0a4935b1bd86653f29acc8fdfa (patch)
treeb48f39f3bbdb95fe6330f16a21a71ffc4638dc6c /tensorflow/java/README.md
parent2e28243adea19433513c18e32d47f803a7a4cfc2 (diff)
Java: Update documentation with instructions for Maven and Windows.
Fixes #7877 Fixes #6926 Change: 151400818
Diffstat (limited to 'tensorflow/java/README.md')
-rw-r--r--tensorflow/java/README.md120
1 files changed, 94 insertions, 26 deletions
diff --git a/tensorflow/java/README.md b/tensorflow/java/README.md
index 20eb6a8265..80c8f588ee 100644
--- a/tensorflow/java/README.md
+++ b/tensorflow/java/README.md
@@ -11,32 +11,95 @@ Java bindings for TensorFlow. ([Javadoc](https://www.tensorflow.org/api_docs/jav
> and/or the [Android
> demo](https://www.tensorflow.org/code/tensorflow/examples/android).
-## Quickstart
+## Quickstart: Using [Apache Maven](https://maven.apache.org)
+
+TensorFlow for Java releases are included in
+[Maven Central](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.tensorflow%22%20AND%20a%3A%22tensorflow%22)
+and support Linux, OS X and Windows. To use it, add the following dependency to
+your project's `pom.xml`:
+
+```xml
+<dependency>
+ <groupId>org.tensorflow</groupId>
+ <artifactId>tensorflow</artifactId>
+ <version>1.1.0-rc0-windows-fix</version>
+</dependency>
+```
+
+That's all. As an example, to create a Maven project for the
+[label image example](https://www.tensorflow.org/code/tensorflow/java/src/main/java/org/tensorflow/examples/LabelImage.java):
+
+1. Create a `pom.xml`:
+
+ ```xml
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.myorg</groupId>
+ <artifactId>label-image</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <properties>
+ <exec.mainClass>org.tensorflow.examples.LabelImage</exec.mainClass>
+ <!-- The LabelImage example code requires at least JDK 1.7. -->
+ <!-- The maven compiler plugin defaults to a lower version -->
+ <maven.compiler.source>1.7</maven.compiler.source>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.tensorflow</groupId>
+ <artifactId>tensorflow</artifactId>
+ <version>1.1.0-rc0-windows-fix</version>
+ </dependency>
+ </dependencies>
+</project>
+ ```
+
+2. Download the [example source](https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/java/src/main/java/org/tensorflow/examples/LabelImage.java)
+ into `src/main/java/org/tensorflow/examples`. On Linux and OS X, the following script should work:
+
+ ```sh
+ mkdir -p src/main/java/org/tensorflow/examples
+ curl -L "https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/java/src/main/java/org/tensorflow/examples/LabelImage.java" -o src/main/java/org/tensorflow/examples/LabelImage.java
+ ```
+
+3. Compile and execute:
+
+ ```sh
+ mvn compile exec:java
+ ```
+
+## Quickstart: Using `java` and `javac`
+
+This section describes how to use TensorFlow armed with just a JDK installation.
1. Download the Java archive (JAR):
- [libtensorflow.jar](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-1.0.0-PREVIEW1.jar)
+ [libtensorflow.jar](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-1.1.0-rc0.jar)
(optionally, the Java sources:
- [libtensorflow-src.jar](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-src-1.0.0-PREVIEW1.jar)).
+ [libtensorflow-src.jar](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-src-1.1.0-rc0.jar)).
2. Download the native library. GPU-enabled versions required CUDA 8 and cuDNN
5.1. For other versions, the native library will need to be built from
source (see below).
- Linux:
- [CPU-only](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-cpu-linux-x86_64-1.0.0-PREVIEW1.tar.gz),
- [GPU-enabled](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-gpu-linux-x86_64-1.0.0-PREVIEW1.tar.gz)
+ [CPU-only](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-cpu-linux-x86_64-1.1.0-rc0.tar.gz),
+ [GPU-enabled](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-gpu-linux-x86_64-1.1.0-rc0.tar.gz)
- OS X:
- [CPU-only](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-cpu-darwin-x86_64-1.0.0-PREVIEW1.tar.gz),
- [GPU-enabled](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-gpu-darwin-x86_64-1.0.0-PREVIEW1.tar.gz)
+ [CPU-only](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-cpu-darwin-x86_64-1.1.0-rc0.tar.gz),
+ [GPU-enabled](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-gpu-darwin-x86_64-1.1.0-rc0.tar.gz)
+ - Windows:
+ [CPU-only](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-cpu-windows-x86_64-1.1.0-rc0.zip)
+
- The following shell snippet downloads and extracts the native library:
+ The following shell snippet downloads and extracts the native library on
+ Linux and OS X. For Windows, download and extract manually.
```sh
TF_TYPE="cpu" # Set to "gpu" to enable GPU support
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
mkdir -p ./jni
curl -L \
- "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-${TF_TYPE}-${OS}-x86_64-1.0.0-PREVIEW1.tar.gz" |
+ "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-${TF_TYPE}-${OS}-x86_64-1.1.0-rc0.tar.gz" |
tar -xz -C ./jni
```
@@ -56,7 +119,7 @@ Java bindings for TensorFlow. ([Javadoc](https://www.tensorflow.org/api_docs/jav
then it should be compiled with:
```sh
- javac -cp libtensorflow-1.0.0-PREVIEW1.jar MyClass.java
+ javac -cp libtensorflow-1.1.0-rc0.jar MyClass.java
```
For a more sophisticated example, see
@@ -65,7 +128,7 @@ Java bindings for TensorFlow. ([Javadoc](https://www.tensorflow.org/api_docs/jav
```sh
javac \
- -cp libtensorflow-1.0.0-PREVIEW1.jar \
+ -cp libtensorflow-1.1.0-rc0.jar \
./src/main/java/org/tensorflow/examples/LabelImage.java
```
@@ -73,7 +136,7 @@ Java bindings for TensorFlow. ([Javadoc](https://www.tensorflow.org/api_docs/jav
library path during execution. For example:
```sh
- java -cp libtensorflow-1.0.0-PREVIEW1.jar:. -Djava.library.path=./jni MyClass
+ java -cp libtensorflow-1.1.0-rc0.jar:. -Djava.library.path=./jni MyClass
```
or for the `LabelImage` example:
@@ -81,17 +144,14 @@ Java bindings for TensorFlow. ([Javadoc](https://www.tensorflow.org/api_docs/jav
```sh
java \
-Djava.library.path=./jni \
- -cp libtensorflow-1.0.0-PREVIEW1.jar:./src/main/java \
+ -cp libtensorflow-1.1.0-rc0.jar:./src/main/java \
org.tensorflow.examples.LabelImage
```
-That's all. These artifacts are not yet available on Maven central, see
-[#6926](https://github.com/tensorflow/tensorflow/issues/6926).
-
## Building from source
-If the quickstart instructions above do not work out, the TensorFlow native
-libraries will need to be built from source.
+If the quickstart instructions above do not work out, the TensorFlow Java and
+native libraries will need to be built from source.
1. Install [bazel](https://www.bazel.build/versions/master/docs/install.html)
@@ -110,6 +170,7 @@ libraries will need to be built from source.
brew install swig
```
+
3. [Configure](https://www.tensorflow.org/install/install_sources#configure_the_installation)
(e.g., enable GPU support) and build:
@@ -120,14 +181,22 @@ libraries will need to be built from source.
//tensorflow/java:libtensorflow_jni
```
-The JAR (`libtensorflow.jar`) and native library (`libtensorflow_jni.so` on Linux or `libtensorflow_jni.dylib` on OS X) will
-be in `bazel-bin/tensorflow/java`. Using these artifacts follow both steps 3 and 4 in the [quickstart](#quickstart) section in order to get your application up and running.
+The JAR (`libtensorflow.jar`) and native library (`libtensorflow_jni.so` on
+Linux, `libtensorflow_jni.dylib` on OS X, `tensorflow_jni.dll` on Windows) will
+be in `bazel-bin/tensorflow/java`. Using these artifacts follow both steps 3
+and 4 in the previous section in order to get your application
+up and running.
+
+Installation on Windows requires the more experimental [bazel on Windows](https://bazel.build/versions/master/docs/windows.html).
+Details are elided here, but find inspiration in the script used for
+building the release archive:
+[`tensorflow/tools/ci_build/windows/libtensorflow_cpu.sh`](https://www.tensorflow.org/code/tensorflow/tools/ci_build/windows/libtensorflow_cpu.sh).
### Maven
-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):
+Details of the release process for Maven Central are in [`maven/README.md`](https://www.tensorflow.org/code/tensorflow/java/maven/README.md).
+However, for development, you can push the library built from source to a local
+Maven repository with:
```sh
bazel build -c opt //tensorflow/java:pom
@@ -136,9 +205,8 @@ mvn install:install-file \
-DpomFile=../../bazel-bin/tensorflow/java/pom.xml
```
-Refer to the library using Maven coordinates. For example, if you're using Maven
-then place this dependency into your `pom.xml` file (replacing 1.0.head with
-the version of the TensorFlow runtime you wish to use).
+And then rever to this library in a project's `pom.xml` with:
+(replacing 1.0.head with the appropriate version):
```xml
<dependency>