You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/10/24 22:25:36 UTC

[GitHub] lanking520 commented on a change in pull request #12969: [MXNET-1160][WIP] add Java build/run example

lanking520 commented on a change in pull request #12969: [MXNET-1160][WIP] add Java build/run example
URL: https://github.com/apache/incubator-mxnet/pull/12969#discussion_r227980670
 
 

 ##########
 File path: docs/tutorials/scala/mxnet_java_install_and_run_examples.md
 ##########
 @@ -0,0 +1,137 @@
+# 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 dependecies.
+
+## Import and run the Java package
+For users using a desktop/laptop, we recommend to use IntelliJ IDE as it is tested and supported to provide necessary documentation for the Java API.
+
+Alternatively, users can follow the second instruction to setup a 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`. It should open a popup window like this :
+
+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 grabbed from Mavel Central. 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 it’s 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());
+
+    }
+}
+```
+
+7. If all went well, you should see an output like this : (Ignore the SLF4J warnings). 
+```
+Hello
+SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
+SLF4J: Defaulting to no-operation (NOP) logger implementation
+SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
+Shape of NDarray is : (10,20)
+Process finished with exit code 0
+```
+This means you have successfully set it up on your machine
+
+### Run the project manually in Maven
+In this example, Maven is being used to create the project. This tutorial referred the [Maven in 5 min](https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html) tutorial.
+
+1. Create a new folder and run the following commands
+```
+mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
+```
+You can specify the `groupId` and `artifactId` to your favourite names. You can also create a maven project using empty archetype.
+
+2. then go to `pom.xml` file in your project folder and add the following content.
+- Change the `osx-x86_64` to `linux-x86_64` if your platform is linux.
+- Change `cpu` into `gpu` if you are using gpu
+- Change the version of your package from `1.3.1` to the matched jar version.
+```xml
+<dependency>
+    <groupId>org.apache.mxnet</groupId>
+    <artifactId>mxnet-full_2.11-osx-x86_64-cpu</artifactId>
+    <version>1.3.1</version>
 
 Review comment:
   Since this tutorial is telling the user to use a package download from somewhere rather than from Maven central, I would not make it general until we have something on Maven central

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services