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,12 +31,10 @@ 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
36
-
> [!TIP]
37
-
> To try GitHub Copilot, you need 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.
38
-
39
38
## Skip to the end
40
39
41
40
You can quickly deploy the sample app in this tutorial and see it running in Azure. Just run the following commands in the [Azure Cloud Shell](https://shell.azure.com), and follow the prompt:
@@ -216,9 +215,6 @@ In this step, you configure GitHub deployment using GitHub Actions. It's just on
216
215
217
216
Like the Tomcat convention, if you want to deploy to the root context of Tomcat, name your built artifact *ROOT.war*.
218
217
219
-
> [!TIP]
220
-
> In **Step 4**, try [letting GitHub Copilot show you the code changes to make](#make-code-changes-using-github-copilot).
221
-
222
218
:::row:::
223
219
:::column span="2":::
224
220
**Step 1:** Back in the App Service page, in the left menu, select **Deployment Center**.
@@ -254,7 +250,20 @@ Like the Tomcat convention, if you want to deploy to the root context of Tomcat,
254
250
:::row-end:::
255
251
:::row:::
256
252
:::column span="2":::
257
-
**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 reponse. 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):**
258
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*.
259
268
1. In the `contextIntialized()` method, find the commented code (lines 29-33) and uncomment it.
260
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.
@@ -480,6 +489,26 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
480
489
481
490
## 5. Modify sample code and redeploy
482
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 reponse. 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
+
483
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*.
484
513
485
514
1. In the `contextIntialized()` method, find the commented code (lines 29-33) and uncomment it.
@@ -494,19 +523,18 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
494
523
495
524
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.
496
525
497
-
> [!TIP]
498
-
> Try [letting GitHub Copilot show you the code changes to make](#make-code-changes-using-github-copilot).
499
-
500
526
1. Back in the codespace terminal, run `azd deploy`.
501
527
502
528
```bash
503
529
azd deploy
504
530
```
505
531
506
-
> [!TIP]
507
-
> You can also just use `azd up` always, which does all of `azd package`, `azd provision`, and `azd deploy`.
508
-
>
509
-
> 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.
510
538
511
539
Having issues? Check the [Troubleshooting section](#troubleshooting).
512
540
@@ -621,25 +649,23 @@ git push origin main
621
649
622
650
See [Set up GitHub Actions deployment from the Deployment Center](deploy-github-actions.md#set-up-github-actions-deployment-from-the-deployment-center).
623
651
624
-
#### Make code changes using GitHub Copilot
625
-
626
-
With 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), you can make the code changes in this tutorial by using Copilot Chat in the codespace. Since GitHub Copilot doesn't give you the same answer every time, the following is just an example:
627
-
628
-
1. In your [codespace](#1-run-the-sample), start a new Copilot chat session in the **Chat** view. The GitHub Copilot chat extension was installed by the container definition (see *.devcontainer/devcontainer.json*).
629
-
630
-
1. Ask, "*@workspace How does the app connect to the database?*"
652
+
#### What can I do with GitHub Copilot in my codespace?
631
653
632
-
Copilot might give you some explanation about the `jdbc/MYSQLDS` data source and how it's configured. For the `@workspace` agent, 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).
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 extensioninthe 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).
633
655
634
-
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.*"
656
+
A few tips for you when you talk to GitHub Copilot:
635
657
636
-
Copilot might show you sample code similar to [the one in this tutorial](#5-deploy-sample-code) 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. However, it won't make the actual change for you. It's up to you to add the suggested code and test it.
658
+
- In a single chat session, the questions and answers build on each other and you can get Gi
659
+
- You can ask GitHub Copilot about a file that you already opened in the editor.
660
+
- To let GitHub Copilot access all of the files in the repository when formulating its answers, start your sentence 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 (if you start your sentence with `@workspace`) even where to make the changes, but it can't make the changes for you. It's up to you to add the suggested code and test it.
637
662
638
-
Here are some other things you can say to fine-tune the answer you get.
663
+
Here are some other things you can say to fine-tune the response you get.
639
664
640
665
* Please change this code to use the data source jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS.
641
-
* Some imports inthis are using javax but I have a Jakarta app.
666
+
* Some imports inyour code are using javax but I have a Jakarta app.
642
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