This article will introduce how to integrate the YMP framework in Java Web engineering. The operation process is based on IntelliJ IDEA as the development environment, and the engineering structure is built using Maven:
IntelliJ IDEA download address: https://www.jetbrains.com/idea/download/
Maven download address: http://maven.apache.org/
Create a project
1. Open the IDEA development environment and click the Create New Project button to start creating a new project wizard, as shown in Figure-1 below:
2. Select the Maven project on the left in the New Project window, then check the Create from archetype option, and finally select the maven-archetype-webapp in the list, click the Next button, as shown in Figure-2:
3. After filling in the Maven project's GroupId, ArtifactId, and Version coordinate information, click the Next button, as shown in Figure-3:
4. After confirming that the Maven path, configuration and project information are correct, click the Next button, as shown in Figure-4:
5. Give your new project a name, click the Finish button to complete the wizard and start creating, as shown in Figure-5:
6. The Maven project creation process takes a little time. When you wait patiently for the console to output BUILD SUCCESS, congratulations on the completion of the new project creation, as shown in Figure-6:
Add YMP framework dependency package
1. Open the project pom.xml file and add dependency configuration, as follows:
<dependency> <groupId>net.ymate</groupId> <artifactId>ymate-platform-webmvc</artifactId> <version>2.0-SNAPSHOT</version></dependency><dependency> <groupId>net.ymate.platform</groupId> <artifactId>ymate-platform-cache</artifactId> <version>2.0-SNAPSHOT</version></dependency>
After adding the dependency configuration, you can see that YMP-related dependency packages will be loaded automatically, as shown in Figure-7:
If you have not installed and compiled YMP framework packages, please check out the previous blog: "Quickly get started with YMP development framework (I): Download and compile YMP framework code"
Configure and integrate YMP framework into web engineering
1. Modify the web.xml file
The YMP framework is initialized through Listener in web projects, and the request and controller mapping is completed through Filter or Servlet, so you need to add relevant configurations to the web.xml file, as shown in Figure-8:
PS:
1. The web.xml of the web project created based on Maven is version 2.3 and needs to be replaced with version 2.4 or above.
2. Two configuration methods are provided, respectively, and Filter is recommended to use Filter to handle requests.
The complete web.xml configuration content is as follows:
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <listener> <listener-class>net.ymate.platform.webmvc.support.WebAppEventListener</listener-class> </listener> <filter> <filter-name>DispatchFilter</filter-name> <filter-class>net.ymate.platform.webmvc.support.DispatchFilter</filter-class> </filter> <filter-mapping> <filter-name>DispatchFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- <servlet> <servlet-name>DispatchServlet</servlet-name> <servlet-class>net.ymate.platform.webmvc.support.DispatchServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>DispatchServlet</servlet-name> <url-pattern>/service/*</url-pattern> </servlet-mapping> --> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
3 Add YMP framework configuration file
Create a new ymp-conf.properties file (this is also the only configuration file of the YMP framework) under the root path of the resource directory resources of the project and edit its contents, as shown in the figure below:
PS:
The ymp.dev_model parameter is to set the current project to run in development mode, and will output more framework logs for easy debugging.
The ymp.autoscan_packages parameter is the package path that sets the frame's automatic scanning.
summary
At this point, we have completed the integration of the YMP framework and JavaWeb engineering, and the next article will introduce the use of the controller in detail.