当前位置 主页 > 网站技术 > 代码类 >

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

    栏目:代码类 时间:2019-09-12 11:10

    环境

    操作系统

          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文件,复制下列代码到文件中

    <?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

      

       Maven -> User Settings -> User Settings ->Browse...->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

      修改<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>