Maven-使用Eclipse创建一个Maven风格的SSM项目

  • 创建maven web项目

    File->New->Other->Maven->Maven Project
  • 设置项目目录

    默认即可
  • 选择Archetype

    选择 maven-archetype-webapp
  • 设置GroupId和Artifact Id

    设置GroupId和Artifact Id,分别是com.how2java和ssm。
    后续配置也是用的这个,所以照着做,别自作聪明改其他的,不然后面走不通
  • 项目截图

    此时项目就创建好了,不过还会报错,接着做后续的一系列操作
  • 创建java 源代码目录

    在上一步的截图中可以发现,没有地方存放java源文件,这个时候就需要按照如下步骤做:
    右键项目->属性->Java Build Path->Libraries->Edit->Workspace default 
    JRE(jdk8)->Finish
  • java源文件目录创建好了

  • pom.xml

    接着复制粘贴pom.xml为下面的代码。 粘贴之后,jsp本来的报错就消失了,不过出来一个新的问题,要求通过Maven更新项目。
    右键项目->Maven->Update Project,会弹出一个对话框,点击Ok,这个问题就消失了。

    <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/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.how2java</groupId>
      <artifactId>ssm</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>war</packaging>
     
      <properties>
        <spring.version>4.1.3.RELEASE</spring.version>
        <pagehelper.version>5.1.2-beta</pagehelper.version>
        <mysql.version>5.1.6</mysql.version>
        <mybatis.spring.version>1.2.3</mybatis.spring.version>
        <mybatis.version>3.1.1</mybatis.version>
        <junit.version>4.12</junit.version>
        <jstl.version>1.2</jstl.version>
        <jsqlparser.version>1.0</jsqlparser.version>
        <jackson.version>1.2.7</jackson.version>
        <servlet-api.version>3.1.0</servlet-api.version>
        <druid.version>1.0.18</druid.version>
        <log4j.version>1.2.16</log4j.version>
        <commons-logging.version>1.2</commons-logging.version>
        <commons-fileupload.version>1.2.1</commons-fileupload.version>
        <commons-io.version>1.3.2</commons-io.version>
        <commons-lang.version>2.6</commons-lang.version>
        <aopalliance.version>1.0</aopalliance.version>
        <mybatis-generator.version>1.3.5</mybatis-generator.version>
      </properties>
     
      <dependencies>
     
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>${junit.version}</version>
        </dependency>
     
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
          <version>${mybatis.version}</version>
        </dependency>
     
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis-spring</artifactId>
          <version>${mybatis.spring.version}</version>
        </dependency>
     
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>${mysql.version}</version>
        </dependency>
     
        <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>druid</artifactId>
          <version>${druid.version}</version>
        </dependency>
     
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>${spring.version}</version>
        </dependency>
     
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-test</artifactId>
          <version>${spring.version}</version>
        </dependency>
     
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
          <version>${spring.version}</version>
        </dependency>
     
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>${spring.version}</version>
        </dependency>
     
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-jdbc</artifactId>
          <version>${spring.version}</version>
        </dependency>
     
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-aspects</artifactId>
          <version>${spring.version}</version>
        </dependency>
        <!-- JSP相关 -->
        <dependency>
          <groupId>jstl</groupId>
          <artifactId>jstl</artifactId>
          <version>${jstl.version}</version>
        </dependency>
     
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>${servlet-api.version}</version>
          <scope>provided</scope>
        </dependency>
     
        <!-- pageHelper -->
        <dependency>
          <groupId>com.github.pagehelper</groupId>
          <artifactId>pagehelper</artifactId>
          <version>${pagehelper.version}</version>
        </dependency>
     
        <!--jsqlparser-->
        <dependency>
          <groupId>com.github.jsqlparser</groupId>
          <artifactId>jsqlparser</artifactId>
          <version>${jsqlparser.version}</version>
        </dependency>
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>${log4j.version}</version>
        </dependency>
     
        <dependency>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
          <version>${commons-logging.version}</version>
        </dependency>
     
        <dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
          <version>${commons-fileupload.version}</version>
        </dependency>
     
        <dependency>
          <groupId>commons-io</groupId>
          <artifactId>commons-io</artifactId>
          <version>${commons-io.version}</version>
        </dependency>
     
        <dependency>
          <groupId>commons-lang</groupId>
          <artifactId>commons-lang</artifactId>
          <version>${commons-lang.version}</version>
        </dependency>
     
        <dependency>
          <groupId>aopalliance</groupId>
          <artifactId>aopalliance</artifactId>
          <version>${aopalliance.version}</version>
        </dependency>
     
        <dependency>
          <groupId>org.mybatis.generator</groupId>
          <artifactId>mybatis-generator-core</artifactId>
          <version>${mybatis-generator.version}</version>
        </dependency>
     
      </dependencies>
     
      <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
          <!-- 资源文件拷贝插件 -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <configuration>
              <encoding>UTF-8</encoding>
            </configuration>
          </plugin>
          <!-- java编译插件 -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
              <encoding>UTF-8</encoding>
            </configuration>
          </plugin>
        </plugins>
        <pluginManagement>
          <plugins>
            <!-- 配置Tomcat插件 -->
            <plugin>
              <groupId>org.apache.tomcat.maven</groupId>
              <artifactId>tomcat7-maven-plugin</artifactId>
              <version>2.2</version>
            </plugin>
          </plugins>
        </pluginManagement>
     
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <includes>
              <include>**/*.properties</include>
              <include>**/*.xml</include>
              <include>**/*.tld</include>
            </includes>
            <filtering>false</filtering>
          </resource>
          <resource>
            <directory>src/main/java</directory>
            <includes>
              <include>**/*.properties</include>
              <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
          </resource>
        </resources>
     
      </build>
     
    </project>
  • web.xml

    首先覆盖web.xml
    把下载下来的xxx/ssm/WebContent/WEB-INF/web.xml
    复制到当前的 ssm/src/main/webapp/web.xml这里
  • jsp 目录

    接着复制jsp目录。 
    千万不要复制lib目录
  • 配置文件

    把3个配置文件复制到ssm/src/main/resources下面
  • java源代码

    把java源代码复制到src/main/java下
  • 关于Category.xml

    按照maven ssm项目风格来说,这个文件本应该放在Resource目录的mapper文件夹下,但是这么做还要修改配置信息,为了避免问题复杂话,而且考虑到即使放在当前位置也是可以正常工作的,所以就暂时不修改它的位置了。
  • 启动Tomcat

    右键点击项目,点击Run As -> Run on Server 启动Tomcat
  • 访问测试地址

    访问如下测试地址:
    http://localhost:8080/ssm/listCategory



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值