1
00:00:00,005 --> 00:00:02,005
- [Narrator] To build our proof of concept,

2
00:00:02,005 --> 00:00:04,008
we need to set up our Dev environment

3
00:00:04,008 --> 00:00:07,000
that has several elements that require

4
00:00:07,000 --> 00:00:09,000
careful configuration.

5
00:00:09,000 --> 00:00:11,001
I already set up the environment,

6
00:00:11,001 --> 00:00:13,000
and we will now take a brief tour,

7
00:00:13,000 --> 00:00:15,000
looking at each of the elements.

8
00:00:15,000 --> 00:00:15,009
First,

9
00:00:15,009 --> 00:00:18,001
let us take a look at Eclipse.

10
00:00:18,001 --> 00:00:20,005
Here, I have created a Maven project

11
00:00:20,005 --> 00:00:22,009
that is linked with Git Repo.

12
00:00:22,009 --> 00:00:24,006
To create this project,

13
00:00:24,006 --> 00:00:27,005
I used Maven Webapp Archetype,

14
00:00:27,005 --> 00:00:30,004
which generates this folder structure.

15
00:00:30,004 --> 00:00:34,007
A key element in Maven projects is pom.xml.

16
00:00:34,007 --> 00:00:37,000
In this, starting from the top,

17
00:00:37,000 --> 00:00:39,001
in line number five and six,

18
00:00:39,001 --> 00:00:42,004
the GROUP_ID is com.hplussport,

19
00:00:42,004 --> 00:00:45,004
and artifact ID is red30.

20
00:00:45,004 --> 00:00:47,009
The packaging in line number seven

21
00:00:47,009 --> 00:00:49,001
is set to war,

22
00:00:49,001 --> 00:00:52,005
which we will deploy on our production server.

23
00:00:52,005 --> 00:00:53,003
After that,

24
00:00:53,003 --> 00:00:55,002
I have included some dependencies

25
00:00:55,002 --> 00:00:57,004
for Java and mysql.

26
00:00:57,004 --> 00:00:59,003
I am finally in build.

27
00:00:59,003 --> 00:01:01,000
The important elements are

28
00:01:01,000 --> 00:01:02,003
these directories.

29
00:01:02,003 --> 00:01:04,009
Source directory in line 54,

30
00:01:04,009 --> 00:01:07,004
test source directory in line 55,

31
00:01:07,004 --> 00:01:11,000
and war source directory in line 70.

32
00:01:11,000 --> 00:01:13,007
These directories should be correctly specified

33
00:01:13,007 --> 00:01:16,007
so that Maven can find these files for testing,

34
00:01:16,007 --> 00:01:18,006
building, and deploying.

35
00:01:18,006 --> 00:01:20,009
Now this project is configured

36
00:01:20,009 --> 00:01:23,006
to run on Tomcat server.

37
00:01:23,006 --> 00:01:24,005
To set it up,

38
00:01:24,005 --> 00:01:27,002
I installed Tomcat on my machine,

39
00:01:27,002 --> 00:01:30,007
and then created a server from within Eclipse.

40
00:01:30,007 --> 00:01:31,005
Then,

41
00:01:31,005 --> 00:01:33,001
I bound the two together,

42
00:01:33,001 --> 00:01:35,007
by going into project,

43
00:01:35,007 --> 00:01:37,004
build path,

44
00:01:37,004 --> 00:01:39,008
configure build path.

45
00:01:39,008 --> 00:01:41,000
From here,

46
00:01:41,000 --> 00:01:42,004
into server,

47
00:01:42,004 --> 00:01:43,005
and you can see

48
00:01:43,005 --> 00:01:47,006
that TomcatDev is associated with project Red30.

49
00:01:47,006 --> 00:01:50,001
You can see some configurations of the server

50
00:01:50,001 --> 00:01:52,003
by going into server view,

51
00:01:52,003 --> 00:01:54,009
and double clicking on the server.

52
00:01:54,009 --> 00:01:57,009
This shows some basic configuration settings,

53
00:01:57,009 --> 00:01:59,009
starting with the server name,

54
00:01:59,009 --> 00:02:02,006
TomcatDev, hosted on local host,

55
00:02:02,006 --> 00:02:06,007
and the configuration path where all these files are stored.

56
00:02:06,007 --> 00:02:08,006
One important aspect here

57
00:02:08,006 --> 00:02:10,003
are these ports.

58
00:02:10,003 --> 00:02:12,003
Make sure these ports are

59
00:02:12,003 --> 00:02:15,003
not clashing with any other applications

60
00:02:15,003 --> 00:02:17,003
running on your machine.

61
00:02:17,003 --> 00:02:19,003
Coming back to these files,

62
00:02:19,003 --> 00:02:22,000
these files have some important configuration settings

63
00:02:22,000 --> 00:02:24,009
which we need to look at.

64
00:02:24,009 --> 00:02:26,004
So starting with

65
00:02:26,004 --> 00:02:28,003
Eclipse project workspace,

66
00:02:28,003 --> 00:02:31,007
you will find a folder named servers,

67
00:02:31,007 --> 00:02:35,008
that has another folder named TomcatDev-config,

68
00:02:35,008 --> 00:02:39,004
if TomcatDev is your Dev server name.

69
00:02:39,004 --> 00:02:41,005
It has several configuration files

70
00:02:41,005 --> 00:02:43,004
and the ones we are interested in

71
00:02:43,004 --> 00:02:44,009
are context.xml,

72
00:02:44,009 --> 00:02:48,007
server.xml, and tomcat-users.xml.

73
00:02:48,007 --> 00:02:51,008
Notice that we won't touch the web.xml in this folder

74
00:02:51,008 --> 00:02:53,008
because it pertains to the server

75
00:02:53,008 --> 00:02:56,003
and not to our application.

76
00:02:56,003 --> 00:02:57,001
First,

77
00:02:57,001 --> 00:02:59,000
let's look at context.xml.

78
00:02:59,000 --> 00:03:01,009
This defines the data source to connect to,

79
00:03:01,009 --> 00:03:04,003
which is red30db database.

80
00:03:04,003 --> 00:03:06,006
I have given it the name DataSource,

81
00:03:06,006 --> 00:03:09,001
and the username and password you see here

82
00:03:09,001 --> 00:03:12,002
are for accessing red30db.

83
00:03:12,002 --> 00:03:14,004
Next, server.xml.

84
00:03:14,004 --> 00:03:16,006
Here you need to specify the ports

85
00:03:16,006 --> 00:03:19,005
that should not clash with any other application.

86
00:03:19,005 --> 00:03:20,004
And finally,

87
00:03:20,004 --> 00:03:24,004
tomcat-users.xml, where you need to add a user

88
00:03:24,004 --> 00:03:26,002
for manager-gui role,

89
00:03:26,002 --> 00:03:29,001
if you want to manage the Tomcat application

90
00:03:29,001 --> 00:03:31,004
using the gui provided by Tomcat.

91
00:03:31,004 --> 00:03:33,006
If not, then you can ignore it.

92
00:03:33,006 --> 00:03:36,006
Now, to the applications web.xml,

93
00:03:36,006 --> 00:03:39,003
which sits inside WEB-INF folder,

94
00:03:39,003 --> 00:03:42,005
inside webapp folder of the application.

95
00:03:42,005 --> 00:03:45,007
What I'm going to set up here in this xml is,

96
00:03:45,007 --> 00:03:49,007
how does the data get loaded from the database.

97
00:03:49,007 --> 00:03:53,003
I want my application to have all data loaded up

98
00:03:53,003 --> 00:03:56,005
before users start interacting with it.

99
00:03:56,005 --> 00:03:59,002
This improves the application performance.

100
00:03:59,002 --> 00:04:01,007
So I'm going to create a servlet

101
00:04:01,007 --> 00:04:03,005
named DataLoader,

102
00:04:03,005 --> 00:04:05,008
that will connect to red30db

103
00:04:05,008 --> 00:04:07,004
and read all the data.

104
00:04:07,004 --> 00:04:08,003
And to do this,

105
00:04:08,003 --> 00:04:11,000
I need to specify here in web.xml,

106
00:04:11,000 --> 00:04:13,009
that it should be loaded on startup.

107
00:04:13,009 --> 00:04:16,007
The number one indicates the sequence

108
00:04:16,007 --> 00:04:18,005
in which it should be loaded.

109
00:04:18,005 --> 00:04:22,003
So these are the settings on the Dev. site.

110
00:04:22,003 --> 00:04:25,003
The Tomcat proj server configuration settings

111
00:04:25,003 --> 00:04:27,002
are quite similar except,

112
00:04:27,002 --> 00:04:31,006
that the config files are not inside Eclipse Workspace,

113
00:04:31,006 --> 00:04:34,005
but inside the base Apache installation folder

114
00:04:34,005 --> 00:04:37,008
on our aws ec2 instance.

115
00:04:37,008 --> 00:04:40,002
So in the Apache root folder,

116
00:04:40,002 --> 00:04:43,004
there is a conf folder with two xml files

117
00:04:43,004 --> 00:04:44,009
which need some configuring.

118
00:04:44,009 --> 00:04:47,001
And then there is webapps folder,

119
00:04:47,001 --> 00:04:50,003
where we will deploy our war file.

120
00:04:50,003 --> 00:04:53,004
This war will explode to create the red30 folder,

121
00:04:53,004 --> 00:04:56,000
which will have all the application files,

122
00:04:56,000 --> 00:04:57,008
as shown here.

123
00:04:57,008 --> 00:05:01,005
The context.xml file remains the same for proj server,

124
00:05:01,005 --> 00:05:04,006
except that the URL for database,

125
00:05:04,006 --> 00:05:07,001
comes from Amazon RDS.

126
00:05:07,001 --> 00:05:09,000
Web.xml also remains the same,

127
00:05:09,000 --> 00:05:13,001
where we specify DataLoader servlet to be loaded on startup,

128
00:05:13,001 --> 00:05:15,006
and in tomcat-users.xml,

129
00:05:15,006 --> 00:05:18,005
we need to add one additional user

130
00:05:18,005 --> 00:05:21,001
that has manager-script role.

131
00:05:21,001 --> 00:05:24,009
This role will allow us to deploy war file into servers

132
00:05:24,009 --> 00:05:28,000
webapps folder through Jenkins.

