diff --git a/tensorflow/java/BUILD b/tensorflow/java/BUILD index 4522c4a59ea..07baa8f3871 100644 --- a/tensorflow/java/BUILD +++ b/tensorflow/java/BUILD @@ -92,6 +92,20 @@ cc_binary( deps = ["//tensorflow/java/src/main/native"], ) +genrule( + name = "pom", + outs = ["pom.xml"], + cmd = "$(location generate_pom) >$@", + output_to_bindir = 1, + tools = [":generate_pom"], +) + +cc_binary( + name = "generate_pom", + srcs = ["generate_pom.cc"], + deps = ["//tensorflow/c:c_api"], +) + # System.loadLibrary() on OS X looks for ".dylib" or ".jnilib" # and no ".so". If and when https://github.com/bazelbuild/bazel/issues/914 # is resolved, perhaps this workaround rule can be removed. diff --git a/tensorflow/java/README.md b/tensorflow/java/README.md index 1811fed73a3..5c5e45d4d87 100644 --- a/tensorflow/java/README.md +++ b/tensorflow/java/README.md @@ -40,22 +40,28 @@ bazel build -c opt \ //tensorflow/java:libtensorflow-jni ``` -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): +### 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): ```sh +bazel build -c opt //tensorflow/java:pom mvn install:install-file \ - -Dfile=bazel-bin/tensorflow/java/libtensorflow.jar \ - -DpomFile=tensorflow/java/pom.xml + -Dfile=../../bazel-bin/tensorflow/java/libtensorflow.jar \ + -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: +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). ```xml org.tensorflow libtensorflow - 0.12.0-SNAPSHOT + 0.12.head ``` diff --git a/tensorflow/java/pom.xml b/tensorflow/java/generate_pom.cc similarity index 70% rename from tensorflow/java/pom.xml rename to tensorflow/java/generate_pom.cc index d3167e0df2b..85f1c56d5b6 100644 --- a/tensorflow/java/pom.xml +++ b/tensorflow/java/generate_pom.cc @@ -1,6 +1,4 @@ - - +==============================================================================*/ + +#include +#include + +#include "tensorflow/c/c_api.h" + +int main(int argc, char** argv) { + std::string tmpl(R"EOF( - + 4.0.0 org.tensorflow libtensorflow - 0.12.0-SNAPSHOT + {{TENSORFLOW_VERSION}} jar - + tensorflow https://www.tensorflow.org 2015 - + The Apache Software License, Version 2.0 @@ -34,11 +40,21 @@ limitations under the License. repo - + https://github.com/tensorflow/tensorflow.git git@github.com:tensorflow/tensorflow.git scm:git:https://github.com/tensorflow/tensorflow.git - + )EOF"); + + const std::string var("{{TENSORFLOW_VERSION}}"); + const std::string val(TF_Version()); + for (size_t pos = tmpl.find(var); pos != std::string::npos; + pos = tmpl.find(var)) { + tmpl.replace(pos, var.size(), val); + } + std::cout << tmpl; + return 0; +}