Add 'apps/arv-web/' from commit 'f9732ad8460d013c2f28363655d0d1b91894dca5'
[arvados.git] / doc / sdk / java / index.html.textile.liquid
1 ---
2 layout: default
3 navsection: sdk
4 navmenu: Java
5 title: "Java SDK"
6
7 ...
8
9 The Java SDK provides a generic set of wrappers so you can make API calls in java.
10
11 h3. Introdution
12
13 * The Java SDK requires Java 6 or later
14   
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. 
18
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
21
22
23 h3. Setting up the environment
24
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.
28
29 <notextile>
30 <pre>
31 ARVADOS_API_TOKEN: API client token to be used to authorize with API server.
32
33 ARVADOS_API_HOST: Host name of the API server.
34
35 ARVADOS_API_HOST_INSECURE: Set this to true if you are using self-signed
36     certificates and would like to bypass certificate validations.
37 </pre>
38 </notextile>
39
40 * Please see "api-tokens":{{site.baseurl}}/user/reference/api-tokens.html for full details.
41           
42
43 h3. Building the Arvados SDK
44
45 <notextile>
46 <pre>
47 $ <code class="userinput">cd $ARVADOS_HOME/sdk/java</code>
48
49 $ <code class="userinput">mvn -Dmaven.test.skip=true clean package</code>
50   This will generate arvados sdk jar file in the target directory
51 </pre>
52 </notextile>
53
54
55 h3. Implementing your code to use SDK
56
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.
62
63 Please use these implementations to see how you would want use the SDK from your java program.
64
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.
67
68 Below are the steps to compile and run these java program.
69
70 * These programs create an instance of Arvados SDK class and use it to
71 make various <code class="userinput">call</code> requests.
72
73 * To compile the examples
74 <notextile>
75 <pre>
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
80 </pre>
81 </notextile>
82
83 * To run the samples
84 <notextile>
85 <pre>
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>
90 </pre>
91 </notextile>
92
93
94 h3. Viewing and Managing SDK logging
95
96 * SDK uses log4j logging
97
98 * The default location of the log file is
99   <code class="userinput">$ARVADOS_HOME/sdk/java/log/arvados_sdk_java.log</code>
100
101 * Update <code class="userinput">log4j.properties</code> file to change name and location of the log file.
102
103 <notextile>
104 <pre>
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.
107
108 Rebuild the SDK:
109 $ <code class="userinput">mvn -Dmaven.test.skip=true clean package</code>
110 </pre>
111 </notextile>
112
113
114 h3. Using the SDK in eclipse
115
116 * To develop in eclipse, you can use the provided <code class="userinput">eclipse project</code>
117
118 * Install "m2eclipse":https://www.eclipse.org/m2e/ plugin in your eclipse
119
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>.
122
123 <notextile>
124 <pre>
125 In Eclipse IDE:
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
129 </pre>
130 </notextile>
131
132
133 * Open the SDK project in eclipse
134 <notextile>
135 <pre>
136 In Eclipse IDE:
137 File -> Import -> Existing Projects into Workspace -> Next -> Browse
138     and select $ARVADOS_HOME/sdk/java
139 </pre>
140 </notextile>