|
1 | 1 | # Java Getting Started Guide |
2 | 2 |
|
3 | | -This guide will help you make your first API call in Java. |
4 | | - |
5 | | -## Java Project Setup |
6 | | - |
7 | | -* OS: This guide is written for Windows 10, however it should also work fine with a Mac |
8 | | -* Installation |
9 | | - * Download and install [Apache Maven](https://maven.apache.org/download.cgi) |
10 | | - * You must add the {apache-maven-dir}/bin directory to your Windows Environment PATH variable |
11 | | - * Download and install the [latest Java Development Kit (JDK)](http://www.oracle.com/technetwork/java/javase/downloads/index.html) |
12 | | - * Download the [PlayFab JavaSDK](https://api.playfab.com/sdks/download/java) |
13 | | - * Download the zip file, and extract it to a location of your choice {PlayFabJavaLocation} |
14 | | -* New Project Setup |
15 | | - * Create a new empty folder for your JavaGettingStarted project {NewProjectFolder} |
16 | | - * Import the PlayFab JavaSDK into this project |
17 | | - * In Windows-Explorer, navigate to [{PlayFabJavaLocation}/PlayFabClientSDK/](https://github.com/PlayFab/JavaSDK/tree/master/PlayFabClientSDK/) |
18 | | - * Select the src folder, and copy it to {NewProjectFolder} |
19 | | - * Create a new empty text file called pom.xml in {NewProjectFolder} |
20 | | - * We will modify this file in the next section |
21 | | - * Create a new empty text file called testTitleData.json in {NewProjectFolder} |
22 | | - * We will modify this file in the next section |
23 | | - * Create a new Windows Environment variable called: PF_TEST_TITLE_DATA_JSON |
24 | | - * The value is the full path of your new {NewProjectFolder}/testTitleData.json file |
25 | | - * Navigate to: {NewProjectFolder}/src/main/java |
26 | | - * Create a new empty text file called GettingStarted.java (Full path: {NewProjectFolder}/src/main/java/GettingStarted.java ) |
27 | | - * We will modify this file in the next section |
28 | | -* PlayFab Installation Complete! |
| 3 | +This tutorial aims to help you get up and running with PlayFab JavaSDK and simple Java program. The goals we persue in this tutorial: |
| 4 | +* Acquire necessary JAR files |
| 5 | +* Add JAR files to the classpath |
| 6 | +* Create minimal Java console application that executes Custom ID Login API Call |
| 7 | + |
| 8 | +## Acquire necessary JAR files |
| 9 | + |
| 10 | +In order to utilize PlayFab JavaSDK we will need PlayFab Client JavaSDK and it's dependency Google GSON. |
| 11 | +You may download PlayFab Client JavaSDK JAR library [here](https://github.com/PlayFab/JavaSDK/tree/versioned/builds). Look for client-sdk-\*.jar and the corresponding Java Doc [Optional but useful]. |
| 12 | +You may download latest Google GSON [here](http://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.0/). Look for gson-\*.jar. |
| 13 | + |
| 14 | +## Project Setup with Intellij Idea |
| 15 | + |
| 16 | +Once you have initialized simple Intellij Idea Java Project, make sure to place necessary JAR files as shown on the picture: |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +The next step is adding JAR files to the classpath. Navigate to File -> Project Structure... as shown on the picture: |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +Navigate to Libraries and add new Java library as shown on the picture: |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +Select the JAR files you have added to the libs folder, then click OK as shown on the picture: |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +If asked for the Module, select the first one in the list. Ensure that all the JAR files were added to the libraries list: |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +## Project Setup with any IDE |
| 37 | + |
| 38 | +The main requirement is to have JAR files added to the classpath. Please, consult with the guide for your IDE on how to add jar files to classpath. |
29 | 39 |
|
30 | 40 | ## Set up your first API call |
31 | 41 |
|
@@ -106,84 +116,11 @@ public class GettingStarted |
106 | 116 | } |
107 | 117 | ``` |
108 | 118 |
|
109 | | -In your favorite text-editor, update the contents of {NewProjectFolder}/pom.xml as follows: |
110 | | - |
111 | | -```XML |
112 | | -<?xml version="1.0" encoding="UTF-8"?> |
113 | | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
114 | | - <modelVersion>4.0.0</modelVersion> |
115 | | - <groupId>com.example</groupId> |
116 | | - <artifactId>PlayFabExample</artifactId> |
117 | | - <version>1.0.0</version> |
118 | | - <prerequisites> |
119 | | - <maven>3.1.9</maven> |
120 | | - </prerequisites> |
121 | | - <properties> |
122 | | - <!-- Eliminates the file encoding warning. Of course, all of your files should probably be UTF-8 nowadays. --> |
123 | | - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
124 | | - <!-- Added to show how the dependency/property report will look at properties --> |
125 | | - <javaLanguage.version>1.7</javaLanguage.version> |
126 | | - <exec.mainClass>GettingStarted</exec.mainClass> |
127 | | - </properties> |
128 | | - <dependencies> |
129 | | - <dependency> |
130 | | - <groupId>junit</groupId> |
131 | | - <artifactId>junit</artifactId> |
132 | | - <version>4.12</version> |
133 | | - <scope>test</scope> |
134 | | - </dependency> |
135 | | - <dependency> |
136 | | - <groupId>com.google.code.gson</groupId> |
137 | | - <artifactId>gson</artifactId> |
138 | | - <version>2.8.0</version> |
139 | | - </dependency> |
140 | | - <!-- Excellent assertion library. Replaces FEST, which is no longer maintained. --> |
141 | | - <!-- http://joel-costigliola.github.io/assertj/ --> |
142 | | - <dependency> |
143 | | - <groupId>org.assertj</groupId> |
144 | | - <artifactId>assertj-core</artifactId> |
145 | | - <version>3.6.2</version> |
146 | | - <scope>test</scope> |
147 | | - </dependency> |
148 | | - </dependencies> |
149 | | - <build> |
150 | | - <plugins> |
151 | | - <plugin> |
152 | | - <groupId>org.apache.maven.plugins</groupId> |
153 | | - <artifactId>maven-compiler-plugin</artifactId> |
154 | | - <version>3.6.1</version> |
155 | | - <configuration> |
156 | | - <source>${javaLanguage.version}</source> |
157 | | - <target>${javaLanguage.version}</target> |
158 | | - </configuration> |
159 | | - </plugin> |
160 | | - </plugins> |
161 | | - </build> |
162 | | -</project> |
163 | | -``` |
164 | | - |
165 | | -In your favorite text-editor, update the contents of {NewProjectFolder}/testTitleData.json as follows: |
166 | | - |
167 | | -```Json |
168 | | -{ |
169 | | - "titleId": "6195", |
170 | | - |
171 | | -} |
172 | | -``` |
173 | | - |
174 | 119 | ## Finish and Execute |
175 | 120 |
|
176 | | -* Open a new command window in the {NewProjectFolder} folder |
177 | | - *  |
178 | | -* In the command window, enter the following command: |
179 | | - * mvn verify exec:java |
180 | | - * You will see a bunch of logs, including PlayFab test results, and finally near the end: |
181 | | - * Congratulations, you made your first successful API call! |
182 | | - * If everything succeeds, and you see the indicated success line, you've succeeded |
183 | | -* At this point, you can start making other api calls, and building your game |
184 | | -* For a list of all available client API calls, see our documentation: |
185 | | - * https://api.playfab.com/ |
186 | | -* Happy coding! |
| 121 | + |
| 122 | + |
| 123 | +To run the application, hit the play button in the top right corner **(1)**. This will start program execution, and output panel will pop up. Locate the debug message **(2)**. This indicates that API call was succesful. At this point, you can start making other api calls, and building your game. For a list of all available client API calls, see our documentation: [https://api.playfab.com/](https://api.playfab.com/) |
187 | 124 |
|
188 | 125 | ## Deconstruct the code |
189 | 126 |
|
@@ -224,16 +161,3 @@ This optional last section describes every line in GettingStarted.java in detail |
224 | 161 | * PlayFab server issue. As with all software, there can be issues. See our [release notes](https://api.playfab.com/releaseNotes/) for updates. |
225 | 162 | * The internet is not 100% reliable. Sometimes the message is corrupted or fails to reach the PlayFab server. |
226 | 163 | * If you are having difficulty debugging an issue, and the information within the error callback is not sufficient, please visit us on our [forums](https://community.playfab.com/index.html) |
227 | | - |
228 | | -pom.xml is a complicated beast |
229 | | - |
230 | | -* There are a few lines relevant to our example |
231 | | - * <exec.mainClass>GettingStarted</exec.mainClass> |
232 | | - * This tells Maven to run our GettingStarted example when we call "mvn exec:java" |
233 | | - * <dependency>...<groupId>com.google.code.gson</groupId> |
234 | | - * PlayFab requires Google gson to operate |
235 | | - * <dependency>...<groupId>junit</groupId>...<scope>test</scope> |
236 | | - * The PlayFab tests included with the project require JUnit to run [Optional, but included for simpler steps] |
237 | | -* Everything else is standard stuff in a Maven pom.xml, and you should [dive into the documentation](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html) for details. |
238 | | - |
239 | | -Finally, see our separate [testTitleData.json documentation](https://github.com/PlayFab/SDKGenerator/blob/master/JenkinsConsoleUtility/testTitleData.md) |
0 commit comments