yzhliu commented on a change in pull request #13162: [MXNET-1198] MXNet Java API URL: https://github.com/apache/incubator-mxnet/pull/13162#discussion_r233610704
########## File path: docs/tutorials/scala/mxnet_java_install_and_run_examples.md ########## @@ -0,0 +1,123 @@ +# Install and run Java Examples + +## Prerequisites: +Please follow the Step 1 in the [Scala configuration](http://mxnet.incubator.apache.org/install/scala_setup.html#setup-instructions) +These should help you install the correct Java version and all dependencies. + +## Run the Java example project +We have provided a general MXNet Java template under `scala-package/mxnet-demo/java-demo` which contains the necessary project files for you to get started. It contains a simple Hello world! equivalent program `JavaSample.java` and a full fledged `ObjectDetection.java `that shows how to run Object Detection on images using MXNet and pre-trained SSD model. + +Alternatively you could build project from scratch following the below instructions. + +## Import and run the Java package +For users using a desktop/laptop, we recommend using IntelliJ IDE as it is tested and supported to provide the necessary documentation for the Java API. + +Alternatively, users can follow the second instruction to set up an empty Maven project for Java. + +### IntelliJ instruction +If you are using a computer with Ubuntu16.04 or Mac, you can install IntelliJ to run the Java package. Please follow the instruction below: + +1. Create a new Java project in IntelliJ. Fire up IntelliJ and click `Create New Project`. + +2. Click `Next`, and in the `Create project from template` window, do not select anything and click `Next` again. + +3. In the next window choose your `Project name` and the `Project location` and click on `Finish`. + +4. Let's add the Java Inference API jars that we build from source. At the top of the window, Go to the `File -> Project Structure`. In the popup window that opens up, click on `Libraries -> +` and select the path to the jar files downloaded. Click `Apply` and then click `OK`. + +6. Create a new Java class under the folder `your-project-name/src`. Let's call this class `JavaSample.java`. Type in the following code snippet and run it. In this code snippet, we create an NDArray object in Java and print its shape. +```java +import org.apache.mxnet.javaapi.Context; +import org.apache.mxnet.javaapi.NDArray; + +public class JavaSample { +public static void main(String[] args) { + System.out.println("Hello"); + NDArray nd = NDArray.ones(Context.cpu(), new int[] {10, 20}); + + System.out.println("Shape of NDarray is : " + nd.shape()); +} +} Review comment: indent ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
