so://phie

game-engine

A lightweight JavaScript game engine
git clone git://soophie.de/game-engine

blob: bc822fa1851eef2cb43b517f5cbf4a3587092747 (13179 bytes)[doc][blame][raw]

1<!DOCTYPE html>

2<html lang="en" dir="ltr">

3 <head>

4 <meta charset="utf-8">

5 <meta name="viewport" content="width=device-width, initial-scale=1.0">

6 <meta name="author" content="typable">

7 <meta name="keywords" content="">

8 <meta name="description" content="">

9 <meta name="robots" content="noindex, nofollow">

10 <meta name="google" content="notranslate">

11 <title>git.typable</title>

12 <link href="/asset/img/favicon.png" rel="shortcut icon" type="image/png">

13 <link href="/asset/css/style.css" rel="stylesheet">

14 <script src="/asset/js/index.js" type="module"></script>

15 </head>

16 <body>

17 <main class="container-fluid">

18 <div class="row">

19 <div class="container">

20 <aside>

21 <h4 data-rel="top">Spring Framework</h4>

22 <ul>

23 <li data-rel="requirements">Requirements</li>

24 <li data-rel="getting-started">Getting Started</li>

25 <li data-rel="configurations">Configurations</li>

26 <li data-rel="start-up">Start Up</li>

27 </ul>

28 </aside>

29 <ul class="breadcrumb">

30 <li><a href="/">Home</a></li>

31 <li><a href="/blog">Blog</a></li>

32 <li>Spring Framework</li>

33 </ul>

34 <h1>Spring Framework</h1>

35 <p class="subline">The following article is a short introduction to the basic setup of a new Spring

36 Web Project. All required dependencies for this project are managed by a

37 <a href="https://stackoverflow.com/a/19516639">Build Tool</a>, in this case,

38 <a href="https://gradle.org">Gradle</a>.</p>

39 <h2 data-ref="requirements">Requirements</h2>

40 <h4>Install Eclipse Plugins</h4>

41 <p>The listed Eclipse Plugins are needed to work on Spring projects smoothly. To check if they are

42 already installed and if not how to install them, check out this article:

43 <a href="">Eclipse - Install Plugins</a></p>

44 <ul class="list">

45 <li>

46 <p>Spring Tools 4 - It provides the functionality to create and launch Spring projects.<br>

47 <a href="https://marketplace.eclipse.org/content/spring-tools-4-aka-spring-tool-suite-4">Eclipse Marketplace</a></p>

48 </li>

49 <li>

50 <p>Eclipse Web Developer Tools - Deliveres HTML, CSS and JS Editors.<br>

51 <a href="https://marketplace.eclipse.org/content/eclipse-web-developer-tools-0">Eclipse Marketplace</a></p>

52 </li>

53 </ul>

54 <div class="space-2"></div>

55 <h4>Prepare Eclipse Workspace</h4>

56 <ul class="list">

57 <li>

58 <p><b>File Association</b><br><br>"JSP and Tag files has the same Syntax as HTML", in this case, we can

59 now associate the default HTML Editor (delivered by the Eclipse Web Developer Tools Plugin)

60 also to the file types .jsp and .tag to let Eclipse now with which Editor these files

61 should be opened.<br><br>More details about the association of file types could be found

62 in this article: <a href="https://help.eclipse.org/2021-03/index.jsp">Eclipse - Manage File Associations</a></p>

63 </li>

64 <div class="space-1"></div>

65 <li>

66 <p><b>Perspective and Views</b><br><br>Web Projects are typically viewed in the Resource Perspective,

67 so if the Perspective is not shown by default, add it to your Eclipse Workspace.<br><br>

68 The needed views for a smooth working process are the following:<br><br>

69 -> &nbsp;Project Explorer<br>

70 -> &nbsp;Boot Dashboard<br>

71 -> &nbsp;Console<br>

72 -> &nbsp;Gradle Tasks<br><br>

73 More about managing Perspectives and Views can be found here:

74 <a href="https://help.eclipse.org/2021-03/index.jsp">Eclipse - Manage Perspectives and Views</a></p>

75 </li>

76 </ul>

77 <h2 data-ref="getting-started">Getting Started</h2>

78 <h4>Project Setup</h4>

79 <p>To create a new Spring project in Eclipse we choose the project type <mark>Spring Starter Project</mark> under

80 the category <mark>Spring Boot</mark>.</p>

81 <p><b>File -> New -> Project... -> Spring Boot -> Spring Starter Project</b></p>

82 <p>The following properties are required to set up our project correctly:</p>

83 <ul class="list list-short">

84 <li>

85 <p><mark>Name</mark> - The name of your project.</p>

86 </li>

87 <li>

88 <p><mark>Type</mark> - The Build Tool to use for the project. In our case, we use Gradle (Buildship 3.x).</p>

89 </li>

90 <li>

91 <p><mark>Java Version</mark> - The Java Version for the project. The currently preferred Version is 11.</p>

92 </li>

93 <li>

94 <p><mark>Group</mark> - Should be the same as the Package path.</p>

95 </li>

96 <li>

97 <p><mark>Artifact</mark> - The name of your startup Java file.</p>

98 </li>

99 <li>

100 <p><mark>Version</mark> - The version of your project.</p>

101 </li>

102 <li>

103 <p><mark>Description</mark> - A short description of your project.</p>

104 </li>

105 <li>

106 <p><mark>Package</mark> - The root package of your project.<br><br>

107 <b class="note">Important:</b> <span>All Java files must be found in the defined root package

108 or a subpackage of them, otherwise Spring is unable to locate these files.</span></p>

109 </li>

110 </ul>

111 <p>Complete the setup wizard by skipping the choose of dependencies and click Finish. Now Eclipse

112 prepares our Spring Project, this could take some time to build up all needed resources.</p>

113 <p>Then this is done the worktree should now contain the following directories and files:</p>

114 <code><pre><span class="p">Tutorial</span>

115 ├ <span class="p">src/main</span>

116 | ├ <span class="p">java</span>

117 | | └ <span class="n">de.innovate.tutorial</span>

118 | | └ <span class="n">TutorialApplication.java</span>

119 | └ <span class="p">resources</span>

120 | └ <span class="n">application.properties</span>

121 ├ <span class="p">gradle</span>

122 | └ ∙∙∙

123 ├ <span class="n">build.gradle</span>

124 ├ <span class="n">gradlew</span>

125 ├ <span class="n">gradlew.bat</span>

126 ├ <span class="n">HELP.md</span>

127 └ <span class="n">settings.gradle</span></pre></code>

128 <p><b class="note">Notice:</b> <span>All <mark>test</mark> directories and files can be deleted.

129 They aren't needed in our working process with Spring.</span></p>

130 <div class="space-2"></div>

131 <h4>Project Building</h4>

132 <p>The basic workspace setup is completed and we can now define the essential dependencies for

133 Spring Web. All required dependencies for our project should be referenced in the build.gradle

134 file. For that replace the content of the <mark>/build.gradle</mark> file with the following code snippet:</p>

135 <code><pre><span class="p">plugins</span> {

136 <span class="n">id</span> <span class="s">'org.springframework.boot'</span> <span class="n">version</span> <span class="s">'2.2.0.RELEASE'</span>

137 <span class="n">id</span> <span class="s">'io.spring.dependency-management'</span> <span class="n">version</span> <span class="s">'1.0.8.RELEASE'</span>

138 <span class="n">id</span> <span class="s">'java'</span>

139}

140<span class="n">group</span> = <span class="s">'de.typable.tutorial'</span>

141<span class="n">version</span> = <span class="s">'0.0.1'</span>

142<span class="n">sourceCompatibility</span> = <span class="s">'11'</span>

143<span class="p">repositories</span> {

144 <span class="n">mavenCentral</span>()

145}

146<span class="p">dependencies</span> {

147 <span class="x">/* Spring Web */</span>

148 <span class="n">implementation</span> <span class="s">'org.springframework.boot:spring-boot-starter-web'</span>

149 <span class="x">/* JSP & JSTL */</span>

150 <span class="n">implementation</span> <span class="s">'org.apache.tomcat.embed:tomcat-embed-jasper:9.0.27'</span>

151 <span class="n">implementation</span> <span class="s">'javax.servlet:jstl:1.2'</span>

152}</pre></code>

153 <p>We have now referenced the elementary dependencies for a Spring Web project. Additional could be

154 added in the dependencies section. More about dependencies and where to find them could be found

155 in this article: <a href="https://docs.gradle.org/current/userguide/core_dependency_management.html">Gradle - Dependencies</a></p>

156 <p>The next step is to build the project with Gradle to download all in the build.gradle defined

157 dependencies. To do that go to the Gradle Tasks View and double-click on build under the build

158 section.</p>

159 <p><b>Gradle Tasks -> [Project] -> build -> build</b></p>

160 <p>During the building process, the current progress will be displayed in the Gradle Executions View

161 and the Console View. The Gradle Executions View is in most cases needless because the Console

162 gives us much clearer feedback about what's happening and what went wrong if the build crashes.

163 To ensure the building process is successful the Console displays the message

164 <mark>BUILD SUCCESSFUL</mark>.</p>

165 <p><b class="note">Tip:</b> <span>Disabling the Gradle Executions View can be done as followed:

166 <b>Window -> Preferences -> Gradle -> Show Executions View</b></span></p>

167 <p>The building process is finished and this has affected our project worktree, because of that, we

168 need to refresh our project. For that, we right-click on the project in the Package Explorer

169 View and click on <mark>Refresh Gradle Project</mark> under the Gradle section. After that, our Spring project

170 is up to date.</p>

171 <p><b>Project Explorer -> [Project] -> Gradle -> Refresh Gradle Project</b></p>

172 <h2 data-ref="configurations">Configurations</h2>

173 <p>To optimize the project to our needs, we configure some properties in the

174 <mark>application.properties</mark> file. This can also be done with XML. More information about

175 XML configuration can be found here:

176 <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html">Spring - XML Configurations</a></p>

177 <p>Add the following properties to <mark>/src/main/resources/application.properties</mark>:</p>

178 <code><pre><span class="p">server.port</span>=<span class="n">8080</span>

179<span class="p">spring.mvc.view.prefix</span>=<span class="n">/WEB-INF/views/</span>

180<span class="p">spring.mvc.view.suffix</span>=<span class="n">.jsp</span>

181<span class="x"># Reload static resources (Temporary)</span>

182<span class="p">spring.resources.static-locations</span>=<span class="n">file:src/main/resources/static/</span></pre></code>

183 <p>Here a short explanation of the properties from above:</p>

184 <ul class="list">

185 <li>

186 <p><mark>server.port</mark> - Defines which <a href="https://de.wikipedia.org/wiki/Port_(Protokoll)">Port</a>

187 is used to listen for incoming requests by the Browser. The default ports are 80

188 (http://) and 443 (https://).<br><br><b class="note">Example:</b> <span>80 -> http://localhost, 443 ->

189 https://localhost, 8080 -> http://localhost:8080</span></p>

190 </li>

191 <li>

192 <p><mark>spring.mvc.view.prefix</mark> - Defines in which directory the server should looking

193 for them to be served HTML, JSP files. The default path is <mark>/WEB-INF/views/</mark>

194 which represents <mark>/src/main/resources/META-INF/resources/WEB-INF/views/</mark>.</p>

195 </li>

196 <li>

197 <p><mark>spring.mvc.view.suffix</mark> - Defines the file type for them to be served files.

198 The default file type is are .jsp and .html.</p>

199 </li>

200 <li>

201 <p><mark>spring.resources.static-locations</mark> - Files in the defined path can be modified

202 without restarting the server to see the changes. It is common to put all resources like

203 CSS, JavaScript and Images in <mark>/src/main/resources/static/</mark>.<br><br>

204 <b class="note">Notice:</b> <span>This is a temporary property only for development</span></p>

205 </li>

206 </ul>

207 <h2 data-ref="start-up">Start Up</h2>

208 <p>Now it's at the time to launch our Spring Web server to confirm all is configured correctly.<br><br>To

209 start the <a href="http://tomcat.apache.org">Apache Tomcat</a> server that provides the basic

210 functionality of a web server which is integrated in our handy Spring Tools Plugin, we go to the

211 <mark>Boot Dashboard</mark> View expand the <mark>local</mark> section and select the project

212 with our predefined name and click on the "Start or restart" button at the top of the View.</p>

213 <p>To confirm the server is started correctly the console should show up the message:

214 <mark>Started TutorialApplication ...</mark></p>

215 <p>Now the Spring Web server is available under the defined port and can be viewed in the Browser of

216 your choice. The page should show the message <mark>Whitelabel Error Page</mark>, this means that

217 no content is currently available.</p>

218 <p>Now everything is ready to build your project.</p>

219 </div>

220 </div>

221 </main>

222 <footer class="container-fluid">

223 <div class="row">

224 <div class="container">

225 <p>&copy; typable 2021</p>

226 <a href="https://www.buymeacoffee.com/typable">Donate</a>

227 <a href="https://typable.dev/imprint">Imprint</a>

228 <a href="https://typable.dev/terms">Terms</a>

229 </div>

230 </div>

231 </footer>

232 </body>

233</html>