eclipse+maven+spring,mvc项目基本搭建

  • 环境

    • 操作系统

      windows10

    • JDK

      jdk1.8.0_192

    • IDE

      Eclipse IDE for Enterprise Java Developers.

      Version: 2019-06 (4.12.0) Build id: 20190614-1200

 

  • 目录结构 

  

  

  • 构建

 1.配置settings.xml

  创建一个settings.xml文件,复制下列代码到文件中

复制代码
 1 <?xml version="1.0" encoding="UTF-8"?>
 2  <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
 3            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4            xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 5   
 6  <!--  本地maven库,路径可以自定义 -->
 7    <localRepository>D:\DxOffice\repository</localRepository>
 8    
 9  <!--   中央maven库 -->
10    <mirrors>
11      <mirror>
12          <id>nexus-aliyun</id>
13          <mirrorOf>*</mirrorOf>
14          <name>Nexus aliyun</name>
15          <url>http://maven.aliyun.com/nexus/content/groups/public</url>
16      </mirror>
17    </mirrors>
18    
19  </settings> ​
复制代码

  配置

   Window -> Preferences

   

    Maven -> User Settings -> User Settings ->Browse...->选择settings.xml所在目录->Apply and Close

  

 2.创建Maven项目

    File -> New ->Maven Project(/Other...->Maven Project -> Next)

     

   

   Next   

  org.apache.maven.archetypes maven-archetype-webapp 1 .0->Next  

  Group Id、Artifact Id、Version、Package -> Finish 

3.修改JRE

  Build Path 

  

  Configure Build Path...

  

  Libraries -> JRE System Library -> Edit

  

  Workspace default JRE ->Finish

  

4.配置pom.xml

初始文件

复制代码
 1 <project xmlns="http://maven.apache.org/POM/4.0.0"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5     <groupId>cn.kihyou</groupId>
 6     <artifactId>SpringDemo</artifactId>
 7     <packaging>war</packaging>
 8     <version>0.0.1-SNAPSHOT</version>
 9     <name>SpringDemo Maven Webapp</name>
10     <url>http://maven.apache.org</url>
11   <dependencies>
12     <dependency>
13       <groupId>junit</groupId>
14       <artifactId>junit</artifactId>
15       <version>3.8.1</version>
16       <scope>test</scope>
17     </dependency>
18   </dependencies>
19   <build>
20     <finalName>SpringDemo</finalName>
21   </build>
22 </project>
复制代码

 

 添加配置

复制代码
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>cn.kihyou</groupId>
    <artifactId>SpringDemo</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>SpringDemo Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <!-- 以上自动生成 -->

    <!-- properties内自定义复用的属性的标签名,${标签名}调用 -->
    <properties>
        <spring.version>4.3.11.Release</spring.version>
    </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>SpringDemo</finalName>

  </build>

</project>
复制代码

 

修改<dependencies></dependcies>内代码如下

复制代码
 1 <dependencies>
 2          <dependency>
 3              <groupId>mysql</groupId>
 4              <artifactId>mysql-connector-java</artifactId>
 5              <version>8.0.17</version>
 6          </dependency>
 7  8          <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
 9          <dependency>
10              <groupId>javax.servlet.jsp</groupId>
11              <artifactId>jsp-api</artifactId>
12              <version>2.2</version>
13              <scope>provided</scope>
14          </dependency>
15 16          <dependency>
17              <groupId>commons-io</groupId>
18              <artifactId>commons-io</artifactId>
19              <version>2.6</version>
20          </dependency>
21 22          <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
23          <dependency>
24              <groupId>commons-fileupload</groupId>
25              <artifactId>commons-fileupload</artifactId>
26              <version>1.4</version>
27          </dependency>
28 29          <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
30          <dependency>
31              <groupId>com.alibaba</groupId>
32              <artifactId>fastjson</artifactId>
33              <version>1.2.59</version>
34          </dependency>
35 36          <dependency>
37              <groupId>jstl</groupId>
38              <artifactId>jstl</artifactId>
39              <version>1.2</version>
40          </dependency>
41 42          <dependency>
43              <groupId>junit</groupId>
44              <artifactId>junit</artifactId>
45              <version>4.11</version>
46              <scope>test</scope>
47          </dependency>
48 49          <dependency>
50              <groupId>javax.servlet</groupId>
51              <artifactId>javax.servlet-api</artifactId>
52              <version>3.1.0</version>
53          </dependency>
54 55          <dependency>
56              <groupId>javax.servlet.jsp</groupId>
57              <artifactId>javax.servlet.jsp-api</artifactId>
58              <version>2.3.1</version>
59          </dependency>
60 61          <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
62          <dependency>
63              <groupId>org.springframework</groupId>
64              <artifactId>spring-webmvc</artifactId>
65              <version>4.3.11.RELEASE</version>
66          </dependency>
67          <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
68          <dependency>
69              <groupId>org.springframework</groupId>
70              <artifactId>spring-jdbc</artifactId>
71  <version>4.3.11.RELEASE</version> 
72 </dependency> 
73 </dependencies>
复制代码

 

  <build></build>内添加<plugins></plugins>,代码如下

复制代码
 1 <plugins>
 2              <plugin>
 3                  <groupId>org.eclipse.jetty</groupId>
 4                  <artifactId>jetty-maven-plugin</artifactId>
 5                  <version>9.3.7.v20160115</version>
 6                  <configuration>
 7                      <httpConnector>
 8                          <port>8081</port>
 9                      </httpConnector>
10                      <webApp>
11                          <contextPath>/${project.artifactId}</contextPath>
12                      </webApp>
13 14                      <contextHandlers>
15                          <!-- 附件目录服务 -->
16                          <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
17                              <contextPath>/image</contextPath>
18                              <resourceBase>D:\DxOffice\workspace\image</resourceBase>
19                          </contextHandler>
20                      </contextHandlers>
21 22                      <encoding>UTF-8</encoding>
23                      <scanIntervalSeconds>10</scanIntervalSeconds>
24                  </configuration>
25 26              </plugin>
27              <!-- 要解决静态文件锁定问题org\eclipse\jetty\jetty-webapp\ -->
28              <!-- org\eclipse\jetty\webapp\webdefault.xml -->
29              <!-- <init-param> -->
30              <!-- <param-name>useFileMappedBuffer</param-name> -->
31              <!-- <param-value>true</param-value> change to false -->
32              <!-- </init-param> -->
33 34              <plugin>
35                  <groupId>org.apache.tomcat.maven</groupId>
36                  <artifactId>tomcat7-maven-plugin</artifactId>
37                  <version>2.2</version>
38                  <configuration>
39                      <path>/${project.artifactId}</path>
40                      <port>8080</port>
41                      <uriEncoding>UTF-8</uriEncoding>
42                      <finalName>${project.artifactId}</finalName>
43                      <server>tomcat7</server>
44                  </configuration>
45              </plugin>
46 47              <plugin>
48                  <groupId>org.apache.maven.plugins</groupId>
49                  <artifactId>maven-compiler-plugin</artifactId>
50                  <version>3.7.0</version>
51 52                  <configuration>
53                      <source>1.8</source>
54                      <target>1.8</target>
55                      <encoding>UTF-8</encoding>
56                  </configuration>
57 58              </plugin>
59          </plugins>
复制代码

 

5.主目录结构搭建  

   

  M

   model

  V

   view

  C

   controller

   service

posted @   木氷  阅读(210)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示