[Turn] Java Web project directory structure

Explanation

Java web directory introduces the basic structure of the project. Record learn java web project structure.

Java web structure

java web project structure, strictly speaking, fall into two categories: one is to compile the project directory structure, is a publishing project directory structure. Engineering release directory structure structure, load unified directory of the web application as a servlet container, and compile the project directory structure in order to facilitate the preparation of the project, modify the temporary structures, need to build tools (ant, maven, gradle, etc.) by the project compiled final Posted structure runtime. Therefore, the project build directory structure is not uniform, and the tools used to compile the relevant (and also configuration).

Published structural engineering

This is the final project directory structure, the structure indicate the following:

-helloapp
 -index.html
 -othersDirs
  -*.html
  -*.css
  -*.png
  - ......
 -WEB-INF
  -web.xml
  -classes
   -pakageName
    -*.class
  -lib
  -otherConfigfile
 -META-INF
  -MANIFEST.MF

As above, generally can be divided into the following parts:

  • Static resource files

Static files need to access resources include jsp, html, css, js, png , ico, gif, conf configuration files, which can be placed anywhere, usually the default is to prevent the main directory, the file path to access the suffix opposing main directory path. Above, index.html relative access path: /index.html , absolute access path is: HTTP: // Domain: Port / helloapp / index.html .

  • Project profiles (deployment descriptor file)

That is one of the main components java web project: web.xml corresponding positions as in the root of the WEB-INF directory. For some basic configuration to configure the project. For example, access control configuration, the default access configuration, filtering configuration, monitoring and other time. The basic format is as follows:


<!--web.xml对于大小写敏感 -->
<?xml version="1.0" encoding="UTF-8"?>
<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID"version="3.0">

<display-name>helloapp</display-name>

<!--上下文传入键值对-->
<context-param>
    <param-name>key</param-name>
    <param-value>value</param-value>
</context-param>

<!--设置web-app默认主页 -->
  <welcome-file-list>  
        <welcome-file>login.html</welcome-file>  
        <welcome-file>index.htm</welcome-file>  
        <welcome-file>index.jsp</welcome-file>  
        <welcome-file>default.html</welcome-file>  
        <welcome-file>default.htm</welcome-file>  
        <welcome-file>default.jsp</welcome-file>  
    </welcome-file-list>

<!--创建servlet对象-->
<servlet>
  <servlet-name>dispatcher</servlet-name>
  <servlet-class>mypack.DispatcherServlet</servlet-class>
</servlet>


<!--提供servlet对象指向-->
<servlet-mapping>
   <servlet-name>dispatcher</servlet-name>
   <url-pattern>/dispatcher</url-pattern>
</servlet-mapping>
</web-app>
  • Dependent, executable file

This is the core part of the java web application, mainly used to implement logic to dynamically create web applications, the dynamic response functions, to achieve some specific java mainly divided into two parts Distribution: is a WEB-INF / lib / *. jar, for the current application requires the use of dependent jar package, the other for the wEB-INF / classes / ... / *. class files for the web project compiled class files, search order for the first look * .jar files in the lib directory and then look for classes / ... / *. class files.

  • web version information,

The release version is generated based on the configuration information automatically generated, and then META-INF / MANIFEST.MF.

Compile the project directory structure

Here mainly introduce two directory structures: a dynamic web application structure eclipse is created by default, is a maven built project directory structure.

  1. Dynamic Web Project structure

eclipse default dynamic structure shown below:

helloapp
-src
 -packageName
  -*.java
-WebContent
  -META-INF
   -MANIFEST.MF
  -WEB-INF
   -web.xml
   -lib
    -*.jar

As described above, divided into two parts: the src corresponding logic implementation specific java portion; WebContent correspond dependence, engineering configuration, static files portion corresponding to the root of the default WebContent release engineering root specific directory structure corresponding relationship can be:

projectName(右键) ——>Properties——>DeployMent Assembly

View, this also can customize the mapping between the (caution).

  1. Maven project structure

maven structure more convenient to build web applications that rely on more convenient, configuration. Below, its basic engineering structures:

helloapp
-src
 -main
  -java
   -pacakgename
    -*.class
  -resources
   -configfile
  -webapp
   -index.html
   -login.jsp
   -othersFolders
   -WEB-INF
    -web.xml
-target
 -generated-files
-pom.xml

The default deployment correspondence is as follows:

source Deploy Path
src/main/java WEB-INF/classes
src/main/resources WEB-INF/classes
src/main/webapp /
src/main/webapp/WEB-INF/WEB-INF WEB-INF / web.xml
maven Dependencies WEB-INF/lib

Pom.xml which is mainly used to configure project dependencies and compile, publish and other version control.

Enjoytoday, EnjoyCoding


---------------------
Author: amiko
Source: CNBLOGS
Original: https: //www.cnblogs.com/amiko/p/7906215.html
Disclaimer: This article author original article, reproduced, please attach Bowen link!
Content analysis By: CSDN, CNBLOG blog articles reprinted a key plug

Guess you like

Origin www.cnblogs.com/admans/p/11566238.html