eclipse+maven+spring mvc项目基本搭建过程

作者:木氷 时间:2022-12-18 03:50:52 

环境

操作系统

windows10

JDK

jdk1.8.0_192

IDE

Eclipse IDE for Enterprise Java Developers.

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

目录结构

eclipse+maven+spring mvc项目基本搭建过程

eclipse+maven+spring mvc项目基本搭建过程

构建

1.配置settings.xml

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


<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<!-- 本地maven库路径 -->
 <localRepository>D:\DxOffice\repository</localRepository>

<!--  中央maven库 -->
 <mirrors>
  <mirror>
    <id>nexus-aliyun</id>
    <mirrorOf>*</mirrorOf>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
  </mirror>
 </mirrors>

</settings>

配置

Window -> Preferences

eclipse+maven+spring mvc项目基本搭建过程

Maven -> User Settings -> User Settings ->Browse...->Apply and Close

eclipse+maven+spring mvc项目基本搭建过程

2.创建Maven项目

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

eclipse+maven+spring mvc项目基本搭建过程

eclipse+maven+spring mvc项目基本搭建过程

Next

eclipse+maven+spring mvc项目基本搭建过程

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

eclipse+maven+spring mvc项目基本搭建过程

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

eclipse+maven+spring mvc项目基本搭建过程

3.修改JRE

Build Path

eclipse+maven+spring mvc项目基本搭建过程

Configure Build Path...

eclipse+maven+spring mvc项目基本搭建过程

Libraries -> JRE System Library -> Edit

eclipse+maven+spring mvc项目基本搭建过程

Workspace default JRE ->Finish

eclipse+maven+spring mvc项目基本搭建过程

4.配置pom.xml

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


<dependencies>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.17</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.2</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.6</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.4</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.59</version>
    </dependency>

    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>javax.servlet.jsp-api</artifactId>
      <version>2.3.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>4.3.11.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
<version>4.3.11.RELEASE</version>
</dependency>
</dependencies>

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


<plugins>
      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.3.7.v20160115</version>
        <configuration>
          <httpConnector>
            <port>8081</port>
          </httpConnector>
          <webApp>
            <contextPath>/${project.artifactId}</contextPath>
          </webApp>

          <contextHandlers>
            <!-- 附件目录服务 -->
            <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
              <contextPath>/image</contextPath>
              <resourceBase>D:\DxOffice\workspace\image</resourceBase>
            </contextHandler>
          </contextHandlers>

          <encoding>UTF-8</encoding>
          <scanIntervalSeconds>10</scanIntervalSeconds>
        </configuration>

      </plugin>
      <!-- 要解决静态文件锁定问题org\eclipse\jetty\jetty-webapp\ -->
      <!-- org\eclipse\jetty\webapp\webdefault.xml -->
      <!-- <init-param> -->
      <!-- <param-name>useFileMappedBuffer</param-name> -->
      <!-- <param-value>true</param-value> change to false -->
      <!-- </init-param> -->

      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <path>/${project.artifactId}</path>
          <port>8080</port>
          <uriEncoding>UTF-8</uriEncoding>
          <finalName>${project.artifactId}</finalName>
          <server>tomcat7</server>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>

        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>UTF-8</encoding>
        </configuration>

      </plugin>
    </plugins>

5.主目录结构搭建

eclipse+maven+spring mvc项目基本搭建过程

M

model

V

view

C

controller

service

总结

以上所述是小编给大家介绍的eclipse+maven+spring mvc项目基本搭建过程,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

来源:https://www.cnblogs.com/kihyou/archive/2019/09/12/11510024.html

标签:eclipse,maven,spring,mvc,项目搭建
0
投稿

猜你喜欢

  • c#实现ini文件读写类分享

    2022-08-31 09:47:48
  • C#递归算法之快速排序

    2021-08-16 21:13:37
  • Java二维数组查找功能代码实现

    2023-01-04 19:47:17
  • Android 自定义View之边缘凹凸的优惠券效果的开发过程

    2021-12-30 07:25:10
  • 基于Java的打包jar、war、ear包的作用与区别详解

    2023-11-17 11:41:13
  • spring aop注解配置代码实例

    2022-02-16 21:13:33
  • Java并发编程中的生产者与消费者模型简述

    2023-02-16 20:33:18
  • C# 多线程对资源读写时如何控制的方法

    2023-07-12 06:45:41
  • Java异常 Factory method'sqlSessionFactory'rew exception;ested exception is java.lang.NoSuchMethodError:

    2022-03-25 15:06:42
  • Java读取并下载网络文件的方法

    2023-03-18 11:47:05
  • Spring整合Quartz实现动态定时器的示例代码

    2022-10-22 06:48:17
  • android中图片的三级缓存cache策略(内存/文件/网络)

    2023-09-04 19:51:59
  • 浅谈java8中map的新方法--replace

    2022-03-11 20:10:30
  • android 分辨率适配的方法

    2023-03-09 09:21:47
  • 如何处理maven仓库中后缀LastUpdated文件

    2022-01-21 22:15:44
  • Android Studio 超级简单的打包生成apk的方法

    2023-08-07 18:57:28
  • SpringBoot 应用程序测试实现方案

    2021-12-18 04:27:54
  • 详解Spring Cloud中Hystrix的请求合并

    2022-07-06 14:53:06
  • C#中String StringBuilder StringBuffer类的用法

    2023-05-21 02:35:50
  • Gradle配置教程之自定义APK名称与输出路径

    2023-03-04 17:35:27
  • asp之家 软件编程 m.aspxhome.com