9 The Java SDK provides a generic set of wrappers so you can make API calls in java.
13 * The Java SDK requires Java 6 or later
15 * The Java SDK is implemented as a maven project. Hence, you would need a working
16 maven environment to be able to build the source code. If you do not have maven setup,
17 you may find the "Maven in 5 Minutes":http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html link useful.
19 * In this document $ARVADOS_HOME is used to refer to the directory where
20 arvados code is cloned in your system. For ex: $ARVADOS_HOME = $HOME/arvados
23 h3. Setting up the environment
25 * The SDK requires a running Arvados API server. The following information
26 about the API server needs to be passed to the SDK using environment
27 variables or during the construction of the Arvados instance.
31 ARVADOS_API_TOKEN: API client token to be used to authorize with API server.
33 ARVADOS_API_HOST: Host name of the API server.
35 ARVADOS_API_HOST_INSECURE: Set this to true if you are using self-signed
36 certificates and would like to bypass certificate validations.
40 * Please see "api-tokens":{{site.baseurl}}/user/reference/api-tokens.html for full details.
43 h3. Building the Arvados SDK
47 $ <code class="userinput">cd $ARVADOS_HOME/sdk/java</code>
49 $ <code class="userinput">mvn -Dmaven.test.skip=true clean package</code>
50 This will generate arvados sdk jar file in the target directory
55 h3. Implementing your code to use SDK
57 * The following two sample programs serve as sample implementations using the SDK.
58 <code class="userinput">$ARVADOS_HOME/sdk/java/ArvadosSDKJavaExample.java</code> is a simple program
59 that makes a few calls to API server.
60 <code class="userinput">$ARVADOS_HOME/sdk/java/ArvadosSDKJavaExampleWithPrompt.java</code> can be
61 used to make calls to API server interactively.
63 Please use these implementations to see how you would want use the SDK from your java program.
65 Also, refer to <code class="userinput">$ARVADOS_HOME/arvados/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java</code>
66 for more sample API invocation examples.
68 Below are the steps to compile and run these java program.
70 * These programs create an instance of Arvados SDK class and use it to
71 make various <code class="userinput">call</code> requests.
73 * To compile the examples
76 $ <code class="userinput">javac -cp $ARVADOS_HOME/sdk/java/target/arvados-sdk-1.0-jar-with-dependencies.jar \
77 ArvadosSDKJavaExample*.java</code>
78 This results in the generation of the ArvadosSDKJavaExample*.class files
79 in the same directory as the java files
86 $ <code class="userinput">java -cp .:$ARVADOS_HOME/sdk/java/target/arvados-sdk-1.0-jar-with-dependencies.jar \
87 ArvadosSDKJavaExample</code>
88 $ <code class="userinput">java -cp .:$ARVADOS_HOME/sdk/java/target/arvados-sdk-1.0-jar-with-dependencies.jar \
89 ArvadosSDKJavaExampleWithPrompt</code>
94 h3. Viewing and Managing SDK logging
96 * SDK uses log4j logging
98 * The default location of the log file is
99 <code class="userinput">$ARVADOS_HOME/sdk/java/log/arvados_sdk_java.log</code>
101 * Update <code class="userinput">log4j.properties</code> file to change name and location of the log file.
105 $ <code class="userinput">nano $ARVADOS_HOME/sdk/java/src/main/resources/log4j.properties</code>
106 and modify the <code class="userinput">log4j.appender.fileAppender.File</code> property as needed.
109 $ <code class="userinput">mvn -Dmaven.test.skip=true clean package</code>
114 h3. Using the SDK in eclipse
116 * To develop in eclipse, you can use the provided <code class="userinput">eclipse project</code>
118 * Install "m2eclipse":https://www.eclipse.org/m2e/ plugin in your eclipse
120 * Set <code class="userinput">M2_REPO</code> classpath variable in eclipse to point to your local repository.
121 The local repository is usually located in your home directory at <code class="userinput">$HOME/.m2/repository</code>.
126 Window -> Preferences -> Java -> Build Path -> Classpath Variables
127 Click on the "New..." button and add a new
128 M2_REPO variable and set it to your local Maven repository
133 * Open the SDK project in eclipse
137 File -> Import -> Existing Projects into Workspace -> Next -> Browse
138 and select $ARVADOS_HOME/sdk/java