3. Prerequisites:
• If you don't have an Azure subscription, create a free
account before you begin.
• Java Development Kit (JDK) 7+.
• Eclipse IDE for Java EE Developers.
• An Azure Web Site with a Java runtime environment (e.g. Tomcat
or Jetty) enabled.
4. What will we
learn?
Create an Azure
Cosmos DB account
Create the Java JSP
application
Install the SQL Java
SDK
Use the Azure
Cosmos DB service
in our Java
application
Wire the rest of the
of Java app
together
Deploy your Java
application to Azure
Web Sites
8. Install the SQL Java SDK
• The easiest way to pull in the SQL Java SDK and its dependencies is through Apache Maven.
1. Right-click your project in the Project Explorer, click Configure, click Convert to Maven Project.
2. In the Create new POM window, accept the defaults, and click Finish.
3. In Project Explorer, open the pom.xml file.
4. On the Dependencies tab, in the Dependencies pane, click Add.
5. In the Select Dependency window, do the following:
• In the Group Id box, enter com.azure
• In the Artifact Id box, enter azure-cosmos.
• In the Version box, enter 4.0.1-beta.1
9.
10. Use the Azure Cosmos DB service in our Java application
• Add a model
- First, we define a model within a new file TodoItem.java.
• Add the Data Access Object(DAO) classes
- Create the cosmosclientfactory class within the CosmosClientFactory.java file
• Create a new TodoDao.java file and add the TodoDao class to create, update, read, and delete the todo items.
• Create a new MockDao.java file and add the MockDao class this implements the ToDoDao class to perform CRUD operations on the items.
• Create a DocdbDao.java file add Docdbdao class. This class defines code to persist the TodoItems into the container, retrieves our database and
collection, if it exists, or create a new one if it doesn't exist.
• Add a Controller
• Create a Servlet
11. Wire the rest of the of Java app together
• Now that we've finished the fun bits, all that's left
is to build a quick user interface and wire it up to
your DAO.
1.We need a web user interface to display to the
user, and rewrite the index.js file.
2.Finally, write some client-side JavaScript to tie
the web user interface and the servlet together.
12. Deploy Java application to Azure
Web Sites
1. Now that you have a WAR file in hand, you can simply upload it to your Azure Web
Site's webapps directory.
2. After the WAR file is uploaded to the webapps directory, the runtime environment will detect that
you've added it and will automatically load it.
3. To view your finished product, navigate to http://YOUR_SITE_NAME.azurewebsites.net/azure-java-
sample/ and start adding your tasks!
14. Where to find
this entire
workshop?
• Refer to: https://docs.microsoft.com/en-
us/azure/cosmos-db/sql-api-java-application
HaimantikaM
Siliguri, India
Haimantika Mitra