7.1. Organising the Folder Structure

After a template-based project has been created, its folder structure will need to be rearranged to suit Spring 4. In the NetBeans 8.2 environment, the steps would be as follows:

  1. Delete the index.html file

  2. Create the WEB-INF folder inside the Web Pages folder

  3. Create the jsp, jspf and resources folders inside the WEB-INF folder

  4. Create the js and CSS folders inside the resources folder

  5. Create the index.jsp file inside the jsp folder

The new structure of the folders should look like this:

fbdevgd30 java 001 en

Figure 43. Folder structure for the template-based project

The WEB-INF/jsp folder will contain jsp pages and the jspf folder will contain page fragments that will be added to other pages using the following directive:

  1. <%@ include file ="<filename>" %>

The resources folder is used to store static web resources — the WEB-INF/resources/css folder for cascading style sheet files, the WEB-INF/resources/fonts folder for font files, the WEB-INF/resources/js folder for JavaScript files and third-party JavaScript libraries.

Now, we modify the pom.xml file and add the general properties of the application, dependencies on library packages (Spring MVC, Jaybird, JDBC pool, JOOQ) and the properties of the JDBC connection.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>ru.ibase</groupId>
  7. <artifactId>fbjavaex</artifactId>
  8. <version>1.0-SNAPSHOT</version>
  9. <packaging>war</packaging>
  10. <name>Firebird Java Example</name>
  11. <properties>
  12. <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
  13. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  14. <spring.version>4.3.20.RELEASE</spring.version>
  15. <jackson.version>2.9.7</jackson.version>
  16. <jooq.version>3.9.2</jooq.version>
  17. <jstl.version>1.2</jstl.version>
  18. <javax.servlet.version>3.0.1</javax.servlet.version>
  19. <jaybird.version>3.0.5</jaybird.version>
  20. <db.url>jdbc:firebirdsql://localhost/examples</db.url>
  21. <db.driver>org.firebirdsql.jdbc.FBDriver</db.driver>
  22. <db.username>SYSDBA</db.username>
  23. <db.password>masterkey</db.password>
  24. </properties>
  25. <dependencies>
  26. <dependency>
  27. <groupId>javax</groupId>
  28. <artifactId>javaee-web-api</artifactId>
  29. <version>7.0</version>
  30. <scope>provided</scope>
  31. </dependency>
  32. <dependency>
  33. <groupId>javax.servlet</groupId>
  34. <artifactId>javax.servlet-api</artifactId>
  35. <version>${javax.servlet.version}</version>
  36. <scope>provided</scope>
  37. </dependency>
  38. <dependency>
  39. <groupId>jstl</groupId>
  40. <artifactId>jstl</artifactId>
  41. <version>${jstl.version}</version>
  42. </dependency>
  43. <!-- Working with JSON -->
  44. <dependency>
  45. <groupId>com.fasterxml.jackson.core</groupId>
  46. <artifactId>jackson-core</artifactId>
  47. <version>${jackson.version}</version>
  48. </dependency>
  49. <dependency>
  50. <groupId>com.fasterxml.jackson.core</groupId>
  51. <artifactId>jackson-annotations</artifactId>
  52. <version>${jackson.version}</version>
  53. </dependency>
  54. <dependency>
  55. <groupId>com.fasterxml.jackson.core</groupId>
  56. <artifactId>jackson-databind</artifactId>
  57. <version>${jackson.version}</version>
  58. </dependency>
  59. <!-- Spring -->
  60. <dependency>
  61. <groupId>org.springframework</groupId>
  62. <artifactId>spring-core</artifactId>
  63. <version>${spring.version}</version>
  64. </dependency>
  65. <dependency>
  66. <groupId>org.springframework</groupId>
  67. <artifactId>spring-web</artifactId>
  68. <version>${spring.version}</version>
  69. </dependency>
  70. <dependency>
  71. <groupId>org.springframework</groupId>
  72. <artifactId>spring-webmvc</artifactId>
  73. <version>${spring.version}</version>
  74. </dependency>
  75. <dependency>
  76. <groupId>org.springframework</groupId>
  77. <artifactId>spring-context</artifactId>
  78. <version>${spring.version}</version>
  79. </dependency>
  80. <dependency>
  81. <groupId>org.springframework</groupId>
  82. <artifactId>spring-jdbc</artifactId>
  83. <version>${spring.version}</version>
  84. </dependency>
  85. <!-- JDBC -->
  86. <dependency>
  87. <groupId>org.firebirdsql.jdbc</groupId>
  88. <artifactId>jaybird-jdk18</artifactId>
  89. <version>${jaybird.version}</version>
  90. </dependency>
  91. <!-- Connection pool -->
  92. <dependency>
  93. <groupId>commons-dbcp</groupId>
  94. <artifactId>commons-dbcp</artifactId>
  95. <version>1.4</version>
  96. </dependency>
  97. <!-- jOOQ -->
  98. <dependency>
  99. <groupId>org.jooq</groupId>
  100. <artifactId>jooq</artifactId>
  101. <version>${jooq.version}</version>
  102. </dependency>
  103. <dependency>
  104. <groupId>org.jooq</groupId>
  105. <artifactId>jooq-meta</artifactId>
  106. <version>${jooq.version}</version>
  107. </dependency>
  108. <dependency>
  109. <groupId>org.jooq</groupId>
  110. <artifactId>jooq-codegen</artifactId>
  111. <version>${jooq.version}</version>
  112. </dependency>
  113. <!-- Testing -->
  114. <dependency>
  115. <groupId>junit</groupId>
  116. <artifactId>junit</artifactId>
  117. <version>4.12</version>
  118. <type>jar</type>
  119. <scope>test</scope>
  120. </dependency>
  121. <dependency>
  122. <groupId>org.springframework</groupId>
  123. <artifactId>spring-test</artifactId>
  124. <version>${spring.version}</version>
  125. <scope>test</scope>
  126. </dependency>
  127. </dependencies>
  128. <build>
  129. <plugins>
  130. <plugin>
  131. <groupId>org.eclipse.jetty</groupId>
  132. <artifactId>jetty-maven-plugin</artifactId>
  133. <version>9.4.12.v20180830</version>
  134. </plugin>
  135. <plugin>
  136. <groupId>org.apache.maven.plugins</groupId>
  137. <artifactId>maven-compiler-plugin</artifactId>
  138. <version>3.8.0</version>
  139. <configuration>
  140. <source>1.8</source>
  141. <target>1.8</target>
  142. <compilerArguments>
  143. <endorseddirs>${endorsed.dir}</endorseddirs>
  144. </compilerArguments>
  145. </configuration>
  146. </plugin>
  147. <plugin>
  148. <groupId>org.apache.maven.plugins</groupId>
  149. <artifactId>maven-war-plugin</artifactId>
  150. <version>3.2.2</version>
  151. <configuration>
  152. <failOnMissingWebXml>false</failOnMissingWebXml>
  153. </configuration>
  154. </plugin>
  155. <plugin>
  156. <groupId>org.apache.maven.plugins</groupId>
  157. <artifactId>maven-dependency-plugin</artifactId>
  158. <version>3.1.1</version>
  159. <executions>
  160. <execution>
  161. <phase>validate</phase>
  162. <goals>
  163. <goal>copy</goal>
  164. </goals>
  165. <configuration>
  166. <outputDirectory>${endorsed.dir}</outputDirectory>
  167. <silent>true</silent>
  168. <artifactItems>
  169. <artifactItem>
  170. <groupId>javax</groupId>
  171. <artifactId>javaee-endorsed-api</artifactId>
  172. <version>7.0</version>
  173. <type>jar</type>
  174. </artifactItem>
  175. </artifactItems>
  176. </configuration>
  177. </execution>
  178. </executions>
  179. </plugin>
  180. </plugins>
  181. </build>
  182. </project>
What is a POM?

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. More details can be found at https://maven.apache.org/guides/introduction/introduction-to-the-pom.

After all the necessary dependencies have been fulfilled, a reload of the POM is recommended, to load all the necessary libraries and avoid errors that might otherwise occur while you are working on the project. This is how it is done in NetBeans:

fbdevgd30 java 002 en

Figure 44. Reloading the POM from NetBeans