You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/sql-api-java-application.md
+36-22Lines changed: 36 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ ms.service: cosmos-db
6
6
ms.subservice: cosmosdb-sql
7
7
ms.devlang: java
8
8
ms.topic: tutorial
9
-
ms.date: 11/05/2019
9
+
ms.date: 05/12/2020
10
10
ms.author: anfeldma
11
11
12
12
---
@@ -31,10 +31,10 @@ This Java application tutorial shows you how to create a web-based task-manageme
31
31
32
32
> [!TIP]
33
33
> This application development tutorial assumes that you have prior experience using Java. If you are new to Java or the [prerequisite tools](#Prerequisites), we recommend downloading the complete [todo](https://github.com/Azure-Samples/documentdb-java-todo-app) project from GitHub and building it using [the instructions at the end of this article](#GetProject). Once you have it built, you can review the article to gain insight on the code in the context of the project.
34
-
>
35
-
>
34
+
>
36
35
37
36
## <aid="Prerequisites"></a>Prerequisites for this Java web application tutorial
37
+
38
38
Before you begin this application development tutorial, you must have the following:
39
39
40
40
* If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
@@ -47,36 +47,48 @@ Before you begin this application development tutorial, you must have the follow
47
47
48
48
If you're installing these tools for the first time, coreservlets.com provides a walk-through of the installation process in the quickstart section of their [Tutorial: Installing TomCat7 and Using it with Eclipse](http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html) article.
49
49
50
-
## <aid="CreateDB"></a>Step 1: Create an Azure Cosmos DB account
50
+
## <aid="CreateDB"></a>Create an Azure Cosmos DB account
51
+
51
52
Let's start by creating an Azure Cosmos DB account. If you already have an account or if you are using the Azure Cosmos DB Emulator for this tutorial, you can skip to [Step 2: Create the Java JSP application](#CreateJSP).
## <aid="CreateJSP"></a>Step 2: Create the Java JSP application
58
+
## <aid="CreateJSP"></a>Create the Java JSP application
59
+
58
60
To create the JSP application:
59
61
60
62
1. First, we'll start off by creating a Java project. Start Eclipse, then click **File**, click **New**, and then click **Dynamic Web Project**. If you don't see **Dynamic Web Project** listed as an available project, do the following: click **File**, click **New**, click **Project**…, expand **Web**, click **Dynamic Web Project**, and click **Next**.
2. Enter a project name in the **Project name** box, and in the **Target Runtime** drop-down menu, optionally select a value (e.g. Apache Tomcat v7.0), and then click **Finish**. Selecting a target runtime enables you to run your project locally through Eclipse.
64
-
3. In Eclipse, in the Project Explorer view, expand your project. Right-click **WebContent**, click **New**, and then click **JSP File**.
65
-
4. In the **New JSP File** dialog box, name the file **index.jsp**. Keep the parent folder as **WebContent**, as shown in the following illustration, and then click **Next**.
65
+
66
+
1. Enter a project name in the **Project name** box, and in the **Target Runtime** drop-down menu, optionally select a value (e.g. Apache Tomcat v7.0), and then click **Finish**. Selecting a target runtime enables you to run your project locally through Eclipse.
67
+
68
+
1. In Eclipse, in the Project Explorer view, expand your project. Right-click **WebContent**, click **New**, and then click **JSP File**.
69
+
70
+
1. In the **New JSP File** dialog box, name the file **index.jsp**. Keep the parent folder as **WebContent**, as shown in the following illustration, and then click **Next**.
66
71
67
72

68
-
5. In the **Select JSP Template** dialog box, for the purpose of this tutorial select **New JSP File (html)**, and then click **Finish**.
69
-
6. When the index.jsp file opens in Eclipse, add text to display **Hello World!** within the existing `<body>` element. The updated `<body>` content should look like the following code:
70
-
71
-
<body>
72
-
<% out.println("Hello World!"); %>
73
-
</body>
74
-
7. Save the index.jsp file.
75
-
8. If you set a target runtime in step 2, you can click **Project** and then **Run** to run your JSP application locally:
76
-
77
-

78
73
79
-
## <aid="InstallSDK"></a>Step 3: Install the SQL Java SDK
74
+
1. In the **Select JSP Template** dialog box, for the purpose of this tutorial select **New JSP File (html)**, and then click **Finish**.
75
+
76
+
1. When the index.jsp file opens in Eclipse, add text to display **Hello World!** within the existing `<body>` element. The updated `<body>` content should look like the following code:
77
+
78
+
```html
79
+
<body>
80
+
<% out.println("Hello World!"); %>
81
+
</body>
82
+
```
83
+
84
+
1. Save the index.jsp file.
85
+
86
+
1. If you set a target runtime in step 2, you can click **Project** and then **Run** to run your JSP application locally:
87
+
88
+

89
+
90
+
## <aid="InstallSDK"></a>Install the SQL Java SDK
91
+
80
92
The easiest way to pull in the SQL Java SDK and its dependencies is through [Apache Maven](https://maven.apache.org/).
81
93
82
94
To do this, you will need to convert your project to a maven project by completing the following steps:
@@ -104,7 +116,8 @@ To do this, you will need to convert your project to a maven project by completi
104
116
6. Click **OK** and Maven will install the SQL Java SDK.
105
117
7. Save the pom.xml file.
106
118
107
-
## <aid="UseService"></a>Step 4: Using the Azure Cosmos DB service in a Java application
119
+
## <aid="UseService"></a>Using the Azure Cosmos DB service in a Java application
120
+
108
121
1. First, let's define the TodoItem object in TodoItem.java:
109
122
110
123
@Data
@@ -338,7 +351,7 @@ To do this, you will need to convert your project to a maven project by completi
338
351
return true;
339
352
}
340
353
341
-
## <aid="Wire"></a>Step 5: Wiring the rest of the of Java application development project together
354
+
## <aid="Wire"></a>Wiring the rest of the of Java application development project together
342
355
Now that we've finished the fun bits - all that's left is to build a quick user interface and wire it up to our DAO.
343
356
344
357
1. First, let's start with building a controller to call our DAO:
@@ -710,7 +723,7 @@ Now that we've finished the fun bits - all that's left is to build a quick user
710
723
5. Awesome! Now all that's left is to test the application. Run the application locally, and add some Todo items by filling in the item name and category and clicking **Add Task**.
711
724
6. Once the item appears, you can update whether it's complete by toggling the checkbox and clicking **Update Tasks**.
712
725
713
-
## <aid="Deploy"></a>Step 6: Deploy your Java application to Azure Web Sites
726
+
## <aid="Deploy"></a>Deploy your Java application to Azure Web Sites
714
727
Azure Web Sites makes deploying Java applications as simple as exporting your application as a WAR file and either uploading it via source control (e.g. Git) or FTP.
715
728
716
729
1. To export your application as a WAR file, right-click on your project in **Project Explorer**, click **Export**, and then click **WAR File**.
@@ -750,3 +763,4 @@ All the samples in this tutorial are included in the [todo](https://github.com/A
750
763
21. In a browser, navigate to `http://localhost:8080/azure-documentdb-java-sample/` and start adding to your task list. Note that if you changed your default port values, change 8080 to the value you selected.
751
764
22. To deploy your project to an Azure web site, see [Step 6. Deploy your application to Azure Web Sites](#Deploy).
0 commit comments