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
@@ -22,6 +22,7 @@ This tutorial shows how to build, configure, and deploy a secure Tomcat applicat
22
22
23
23
* An Azure account with an active subscription. If you don't have an Azure account, you [can create one for free](https://azure.microsoft.com/free/java/).
24
24
* Knowledge of Java with Tomcat development.
25
+
***(Optional)** To try GitHub Copilot, a [GitHub Copilot account](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor). A 30-day free trial is available.
25
26
26
27
::: zone-end
27
28
@@ -30,6 +31,7 @@ This tutorial shows how to build, configure, and deploy a secure Tomcat applicat
30
31
* An Azure account with an active subscription. If you don't have an Azure account, you [can create one for free](https://azure.microsoft.com/free/java).
31
32
*[Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd) installed. You can follow the steps with the [Azure Cloud Shell](https://shell.azure.com) because it already has Azure Developer CLI installed.
32
33
* Knowledge of Java with Tomcat development.
34
+
***(Optional)** To try GitHub Copilot, a [GitHub Copilot account](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor). A 30-day free trial is available.
33
35
34
36
::: zone-end
35
37
@@ -84,6 +86,12 @@ First, you set up a sample data-driven app as a starting point. For your conveni
84
86
:::column-end:::
85
87
:::row-end:::
86
88
89
+
> [!TIP]
90
+
> You can ask [GitHub Copilot](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor) about this repository. For example:
91
+
>
92
+
> **@workspace What does this project do?*
93
+
> **@workspace What does the .devcontainer folder do?*
94
+
87
95
Having issues? Check the [Troubleshooting section](#troubleshooting).
88
96
89
97
::: zone pivot="azure-portal"
@@ -242,7 +250,20 @@ Like the Tomcat convention, if you want to deploy to the root context of Tomcat,
242
250
:::row-end:::
243
251
:::row:::
244
252
:::column span="2":::
245
-
**Step 4:**
253
+
**Step 4 (Option 1: with GitHub Copilot):**
254
+
1. Start a new chat session by clicking the **Chat** view, then clicking **+**.
255
+
1. Ask, "*@workspace How does the app connect to the database?*". Copilot might give you some explanation about the `jdbc/MYSQLDS` data source and how it's configured.
256
+
1. Ask, "*@workspace I want to replace the data source defined in persistence.xml with an existing JNDI data source in Tomcat but I want to do it dynamically.*". Copilot might give you a code suggestion similar to the one in the **Option 2: without GitHub Copilot** steps below and even tell you to make the change in the [ContextListener](https://github.com/Azure-Samples/msdocs-tomcat-mysql-sample-app/blob/starter-no-infra/src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java) class.
257
+
1. Open *src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java* in the explorer and add the code suggestion in the `contextInitialized` method.
258
+
GitHub Copilot doesn't give you the same response every time, you might need to add additional questions to fine-tune its response. For tips, see [What can I do with GitHub Copilot in my codespace?](#what-can-i-do-with-github-copilot-in-my-codespace)
259
+
:::column-end:::
260
+
:::column:::
261
+
:::image type="content" source="media/tutorial-java-tomcat-mysql-app/github-copilot-1.png" alt-text="A screenshot showing how to ask a question in a new GitHub Copilot chat session." lightbox="media/tutorial-java-tomcat-mysql-app/github-copilot-1.png":::
262
+
:::column-end:::
263
+
:::row-end:::
264
+
:::row:::
265
+
:::column span="2":::
266
+
**Step 4 (Option 2: without GitHub Copilot):**
246
267
1. Open *src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java* in the explorer. When the application starts, this class loads the database settings in *src/main/resources/META-INF/persistence.xml*.
247
268
1. In the `contextIntialized()` method, find the commented code (lines 29-33) and uncomment it.
248
269
This code checks to see if the `AZURE_MYSQL_CONNECTIONSTRING` app setting exists, and changes the data source to `java:comp/env/jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS`, which is the data source you found earlier in *context.xml* in the SSH shell.
@@ -468,6 +489,26 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
468
489
469
490
## 5. Modify sample code and redeploy
470
491
492
+
# [With GitHub Copilot](#tab/copilot)
493
+
494
+
1. Back in the GitHub codespace of your sample fork, start a new chat session by clicking the **Chat** view, then clicking **+**.
495
+
496
+
1. Ask, "*@workspace How does the app connect to the database?*". Copilot might give you some explanation about the `jdbc/MYSQLDS` data source and how it's configured.
497
+
498
+
1. Ask, "*@workspace I want to replace the data source defined in persistence.xml with an existing JNDI data source in Tomcat but I want to do it dynamically.*". Copilot might give you a code suggestion similar to the one in the **Option 2: without GitHub Copilot** steps below and even tell you to make the change in the [ContextListener](https://github.com/Azure-Samples/msdocs-tomcat-mysql-sample-app/blob/starter-no-infra/src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java) class.
499
+
500
+
1. Open *src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java* in the explorer and add the code suggestion in the `contextInitialized` method.
501
+
502
+
GitHub Copilot doesn't give you the same response every time, you might need to add additional questions to fine-tune its response. For tips, see [What can I do with GitHub Copilot in my codespace?](#what-can-i-do-with-github-copilot-in-my-codespace)
503
+
504
+
1. Back in the codespace terminal, run `azd deploy`.
505
+
506
+
```bash
507
+
azd deploy
508
+
```
509
+
510
+
# [Without GitHub Copilot](#tab/nocopilot)
511
+
471
512
1. Back in the GitHub codespace of your sample fork, from the explorer, open *src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java*. When the application starts, this class loads the database settings in*src/main/resources/META-INF/persistence.xml*.
472
513
473
514
1. In the `contextIntialized()` method, find the commented code (lines 29-33) and uncomment it.
@@ -488,10 +529,12 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
488
529
azd deploy
489
530
```
490
531
491
-
> [!TIP]
492
-
> You can also just use `azd up` always, which does all of `azd package`, `azd provision`, and `azd deploy`.
493
-
>
494
-
> To find out how the War file is packaged, you can run `azd package --debug` by itself.
532
+
-----
533
+
534
+
> [!TIP]
535
+
> You can also just use `azd up` always, which does all of `azd package`, `azd provision`, and `azd deploy`.
536
+
>
537
+
> To find out how the War file is packaged, you can run `azd package --debug` by itself.
495
538
496
539
Having issues? Check the [Troubleshooting section](#troubleshooting).
497
540
@@ -606,6 +649,24 @@ git push origin main
606
649
607
650
See [Set up GitHub Actions deployment from the Deployment Center](deploy-github-actions.md#set-up-github-actions-deployment-from-the-deployment-center).
608
651
652
+
#### What can I do with GitHub Copilot in my codespace?
653
+
654
+
You might have noticed that the GitHub Copilot chat view was already there foryou when you created the codespace. For your convenience, we include the GitHub Copilot chat extensionin the container definition (see *.devcontainer/devcontainer.json*). However, you need a [GitHub Copilot account](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor) (30-day free trial available).
655
+
656
+
A few tips for you when you talk to GitHub Copilot:
657
+
658
+
- In a single chat session, the questions and answers build on each other and you can adjust your questions to fine-tune the answer you get.
659
+
- By default, GitHub Copilot doesn't have access to any file in your repository. You can ask it questions about a file, open the file in the editor first.
660
+
- To let GitHub Copilot have access to all of the files in the repository when preparing its answers, begin your question with `@workspace`. For more information, see [Use the @workspace agent](https://github.blog/2024-03-25-how-to-use-github-copilot-in-your-ide-tips-tricks-and-best-practices/#10-use-the-workspace-agent).
661
+
- In the chat session, GitHub Copilot can suggest changes and (with `@workspace`) even where to make the changes, but it's not allowed to make the changes for you. It's up to you to add the suggested changes and test it.
662
+
663
+
Here are some other things you can say to fine-tune the answer you get.
664
+
665
+
* Please change this code to use the data source jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS.
666
+
* Some imports in your code are using javax but I have a Jakarta app.
667
+
* I want this code to run only if the environment variable AZURE_MYSQL_CONNECTIONSTRING is set.
668
+
* I want this code to run only in Azure App Service and not locally.
0 commit comments