Skip to content

Commit ca641fd

Browse files
author
Yoshio Terada
committed
Updated README.md
Added explanation how to deploy the Java Web App to Tomcat.
1 parent a422d54 commit ca641fd

5 files changed

Lines changed: 256 additions & 21 deletions

File tree

README.md

Lines changed: 256 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ In order to install and create the MySQL, please refer to the following document
7171
## Create Maven Project for Java Web App
7272

7373
```bash
74-
mvn archetype:generate -DarchetypeGroupId=de.rieckpil.archetypes \
74+
mvn archetype:generate \
75+
-DarchetypeGroupId=de.rieckpil.archetypes \
7576
-DarchetypeArtifactId=javaee8-jsf \
7677
-DarchetypeVersion=1.0.1 \
77-
-DgroupId=com.microsoft.azure.samples \
78-
-Dpackage=com.microsoft.azure.samples \
79-
-Dversion=0.0.1-SNAPSHOT \
80-
-DartifactId=azure-javaweb-app \
81-
-Darchetype.interactive=false \
82-
--batch-mode \
78+
-DgroupId=com.microsoft.azure.samples \
79+
-Dpackage=com.microsoft.azure.samples \
80+
-Dversion=0.0.1-SNAPSHOT \
81+
-DartifactId=azure-javaweb-app \
82+
-Darchetype.interactive=false \
83+
--batch-mode
8384
```
8485

8586
```bash
@@ -118,6 +119,28 @@ The above directory structure will be automatically created and it is created to
118119

119120
## Modify the pom.xml file
120121

122+
### Modify
123+
124+
```xml
125+
<maven.compiler.source>11</maven.compiler.source>
126+
<maven.compiler.target>11</maven.compiler.target>
127+
```
128+
129+
### Delete
130+
131+
```xml
132+
<repositories>
133+
<repository>
134+
<id>prime-repo</id>
135+
<name>PrimeFaces Maven Repository</name>
136+
<url>http://repository.primefaces.org</url>
137+
<layout>default</layout>
138+
</repository>
139+
</repositories>
140+
```
141+
142+
### Modify
143+
121144
```
122145
<?xml version="1.0" encoding="UTF-8"?>
123146
@@ -347,51 +370,263 @@ After finished the command, you will be able to see following additional configu
347370
</plugin>
348371
```
349372

373+
### You can modify the name of Azure Resource Group and location
374+
375+
The above configuration will create and deploy to the following environment.
376+
377+
* Azure Resoure Group : `azure-javaweb-app-1595955014168-rg`
378+
* Azure Resource Name : `azure-javaweb-app-1595955014168`
379+
* Azure Resoruce Location : `westeurope`
380+
381+
If you would like to change the Resource Group Name, Resource Name and Location, you can change the configuration like follows.
382+
383+
```
384+
<configuration>
385+
<schemaVersion>V2</schemaVersion>
386+
<resourceGroup>azure-javaweb-app</resourceGroup>
387+
<appName>azure-javaweb-app</appName>
388+
<pricingTier>P1v2</pricingTier>
389+
<region>japaneast</region>
390+
<runtime>
391+
```
392+
393+
## Modify the Java Source Code
394+
395+
```
396+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
397+
xmlns:p="http://primefaces.org/ui">
398+
399+
<h:head>
400+
<title>Hello World JSF 2.3</title>
401+
</h:head>
402+
403+
<h:body>
404+
<p:outputPanel style="display:block">
405+
<h3 style="text-align: center">#{sampleBean.message}</h3>
406+
</p:outputPanel>
407+
</h:body>
408+
409+
</html>
410+
```
411+
412+
Please remove following from html tag?
413+
`xmlns:o="http://omnifaces.org/ui"
414+
xmlns:of="http://omnifaces.org/functions"`
415+
416+
417+
```
418+
package sample;
419+
420+
import javax.enterprise.context.RequestScoped;
421+
import javax.inject.Named;
422+
423+
@Named
424+
@RequestScoped
425+
public class SampleBean {
426+
427+
private String message;
428+
429+
public String getMessage() {
430+
message = "Hello World";
431+
return message;
432+
}
433+
}
434+
```
435+
436+
## Deploy and Run on Local Environment
437+
438+
After you implemented the above code, you can deploy to the Tomcat in Local.
439+
If you access to Tomcat server from Browser, you can see like following.s
440+
441+
![Application Running on Local Tomcat](./images/local-tomcat.png)
442+
350443

351444
## Deploy Java Web App to Azure App Service
352445

353-
-------------------
354-
TODO: Execute Again for this
355-
-------------------
446+
If you would like to deploy the Java Web App to Azure, you can execute the following command.
447+
448+
`mvn azure-webapp:deploy`
449+
450+
Following is the example of the command.
356451

357452
```
358-
https://azure-javaweb-app.azurewebsites.net/
453+
$ mvn clean package azure-webapp:deploy
454+
[INFO] Scanning for projects...
455+
[INFO]
456+
[INFO] -----------< com.microsoft.azure.samples:azure-javaweb-app >------------
457+
[INFO] Building azure-javaweb-app 0.0.1-SNAPSHOT
458+
[INFO] --------------------------------[ war ]---------------------------------
459+
[INFO]
460+
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ azure-javaweb-app ---
461+
[INFO] Deleting /Users/yoterada/azure-javaweb-app/target
462+
463+
[INFO] --- azure-webapp-maven-plugin:1.9.1:deploy (default-cli) @ azure-javaweb-app ---
464+
[INFO] Auth Type : AZURE_CLI, Auth Files : [/Users/yoterada/.azure/azureProfile.json, /Users/yoterada/.azure/accessTokens.json]
465+
[INFO] [Correlation ID: 3a3d53b9-7f39-4e46-b42f-3d4c91ed34df] Instance discovery was successful
466+
[INFO] Subscription : Microsoft Azure Internal Billing-CDA(f77aafe8-6be4-4d3d-bd9c-d0c37687ef70)
467+
[INFO] Target Web App doesn't exist. Creating a new one...
468+
[INFO] Creating App Service Plan 'ServicePlan2932ed54-b243-4c68'...
469+
[INFO] Successfully created App Service Plan.
470+
[INFO] Successfully created Web App.
471+
[INFO] Using 'UTF-8' encoding to copy filtered resources.
472+
[INFO] Copying 1 resource to /Users/yoterada/azure-javaweb-app/target/azure-webapp/azure-javaweb-app-1596171354654-22bf0c41-c96b-4ef9-a96a-4b48de368374
473+
[INFO] Trying to deploy artifact to azure-javaweb-app-1596171354654...
474+
[INFO] Deploying the war file azure-javaweb-app.war...
475+
[INFO] Successfully deployed the artifact to https://azure-javaweb-app-1596171354654.azurewebsites.net
476+
[INFO] ------------------------------------------------------------------------
477+
[INFO] BUILD SUCCESS
478+
[INFO] ------------------------------------------------------------------------
479+
[INFO] Total time: 07:55 min
480+
[INFO] Finished at: 2020-07-31T14:23:01+09:00
481+
[INFO] ------------------------------------------------------------------------
359482
```
360483

484+
If you acces to the URL in the above logs, you can see the following screen.
361485

486+
```
487+
[INFO] Successfully deployed the artifact to
488+
https://azure-javaweb-app-1596171354654.azurewebsites.net
489+
```
362490

363-
### If you configure the `Deployment Slot`, it will be following result
491+
![Java Web App Running on Azure App Service Linux Tomcat](./images/azure-tomcat.png)
364492

365-
If you configure the `Deployment Slot`, following XML will be added to the above XML definition.
493+
494+
## Deploy the Java Web App to Staging Environment (Deployment Slot)
495+
496+
If you execute the `mvn azure-webapp:config` command again, you can configure the [DeploymentSlot](https://docs.microsoft.com/azure/app-service/deploy-staging-slots?WT.mc_id=docs-github-yoterada) as follows.
497+
498+
### Configure the Deployment Slot
499+
500+
```
501+
$ mvn azure-webapp:config
502+
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
503+
[INFO] Scanning for projects...
504+
[INFO]
505+
[INFO] -----------< com.microsoft.azure.samples:azure-javaweb-app >------------
506+
[INFO] Building azure-javaweb-app 0.0.1-SNAPSHOT
507+
[INFO] --------------------------------[ war ]---------------------------------
508+
[INFO]
509+
[INFO] --- azure-webapp-maven-plugin:1.9.1:config (default-cli) @ azure-javaweb-app ---
510+
Please choose which part to config
511+
1. Application
512+
2. Runtime
513+
3. DeploymentSlot
514+
Enter index to use: 3
515+
Deploy to slot?(Y/N): y
516+
Define value for slotName(Default: azure-javaweb-app-1596171354654-slot):
517+
Define value for configurationSource:
518+
Please confirm webapp properties
519+
AppName : azure-javaweb-app-1596171354654
520+
ResourceGroup : azure-javaweb-app-1596171354654-rg
521+
Region : westeurope
522+
PricingTier : PremiumV2_P1v2
523+
OS : Linux
524+
RuntimeStack : TOMCAT 9.0-java11
525+
Deploy to slot : true
526+
Slot name : azure-javaweb-app-1596171354654-slot
527+
ConfigurationSource :
528+
Confirm (Y/N)? : y
529+
[INFO] Saving configuration to pom.
530+
[INFO] ------------------------------------------------------------------------
531+
[INFO] BUILD SUCCESS
532+
[INFO] ------------------------------------------------------------------------
533+
[INFO] Total time: 02:15 min
534+
[INFO] Finished at: 2020-07-31T14:44:33+09:00
535+
[INFO] ------------------------------------------------------------------------
536+
$
537+
```
538+
539+
After finished the above command, you can see the following XML in the `pom.xml`.
366540

367541
```xml
368542
<deploymentSlot>
369-
<name>staging-slot</name>
543+
<name>azure-javaweb-app-1596171354654-slot</name>
370544
<configurationSource></configurationSource>
371545
</deploymentSlot>
372546
```
373547

374-
And If you executed the `mvn azure-webapp:deploy` command, new `Deployment Slot` will be automatically created and deploy the Web App to it.
548+
### Deploy the Java Web App the Deployment Slot
549+
550+
After the configuration, if you executed the `mvn azure-webapp:deploy` command, new `Deployment Slot` will be automatically created and deploy the Web App to it.
551+
552+
Please modify the source code like follows.
553+
554+
```java
555+
package sample;
556+
557+
import javax.enterprise.context.RequestScoped;
558+
import javax.inject.Named;
559+
560+
@Named
561+
@RequestScoped
562+
public class SampleBean {
563+
564+
private String message;
565+
566+
public String getMessage() {
567+
message = "Hello World 2";
568+
return message;
569+
}
570+
}
571+
```
572+
573+
Then, you build the new package and deploy it to the Deployment Slot?
375574

376575
```bash
377-
$ mvn azure-webapp:deploy
576+
$ mvn clean package azure-webapp:deploy
577+
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
578+
[INFO] Scanning for projects...
579+
[INFO]
580+
[INFO] -----------< com.microsoft.azure.samples:azure-javaweb-app >------------
581+
[INFO] Building azure-javaweb-app 0.0.1-SNAPSHOT
582+
[INFO] --------------------------------[ war ]---------------------------------
583+
[INFO]
584+
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ azure-javaweb-app ---
585+
[INFO] Deleting /Users/yoterada/azure-javaweb-app/target
586+
587+
[INFO] [Correlation ID: a533c9be-a1b8-4209-b789-a43016e5827c] Instance discovery was successful
588+
[INFO] Subscription : Microsoft Azure Internal Billing-CDA(f77aafe8-6be4-4d3d-bd9c-d0c37687ef70)
589+
[INFO] Updating target Web App...
590+
[INFO] Successfully updated Web App.
378591
[INFO] Target Deployment Slot doesn't exist. Creating a new one...
379592
[INFO] Creating a new deployment slot and copying configuration from parent...
380593
[INFO] Successfully created the Deployment Slot.
381594
[INFO] Using 'UTF-8' encoding to copy filtered resources.
382-
[INFO] Copying 1 resource to /private/tmp/TMP/azure-javaweb-app/target/azure-webapp/azure-javaweb-app-8c4fb3f9-d8e5-4d62-85ab-8ffe6248387f
383-
[INFO] Trying to deploy artifact to staging-slot...
595+
[INFO] Copying 1 resource to /Users/yoterada/azure-javaweb-app/target/azure-webapp/azure-javaweb-app-bcdbe5b1-78a3-47c5-9b8f-567a4e16911e
596+
[INFO] Trying to deploy artifact to azure-javaweb-app-1596171354654-slot...
384597
[INFO] Deploying the war file azure-javaweb-app.war...
385-
[INFO] Successfully deployed the artifact to https://azure-javaweb-app-staging-slot.azurewebsites.net
598+
[INFO] Successfully deployed the artifact to https://azure-javaweb-app-azure-javaweb-app-1596171354654-slot.azurewebsites.net
386599
[INFO] ------------------------------------------------------------------------
387600
[INFO] BUILD SUCCESS
388601
[INFO] ------------------------------------------------------------------------
389-
[INFO] Total time: 01:46 min
390-
[INFO] Finished at: 2020-07-29T02:01:11+09:00
602+
[INFO] Total time: 02:15 min
603+
[INFO] Finished at: 2020-07-31T14:52:53+09:00
391604
[INFO] ------------------------------------------------------------------------
392605
```
393606
607+
Then you can see the follogin logs.
608+
609+
```
610+
[INFO] Successfully deployed the artifact to https://azure-javaweb-app-azure-javaweb-app-1596171354654-slot.azurewebsites.net
611+
```
612+
613+
![Java Web App Running on Azure App Service Linux Tomcat Deployment Slot](./images/azure-tomcat-deployment-slot.png)
614+
615+
616+
Azure Deployment Slot is very useful for evaluation, and you can create multiple deployment slot like follows.
617+
618+
![Deployment Slot](./images/azure-portal-deployment-slot.png)
619+
620+
621+
# Implement DB Access code from Web Application
622+
623+
## Explain how to implement JSF (PrimeFaces)
624+
625+
TBD
626+
627+
## Explain how to implement JPA which access to MySQL
394628
629+
TBD
395630
396631
## Final Directory Structure of this Project
397632
403 KB
Loading
297 KB
Loading

images/azure-tomcat.png

298 KB
Loading

images/local-tomcat.png

285 KB
Loading

0 commit comments

Comments
 (0)