Eclipse中使用Maven创建Java Web工程的实现方式

 更新时间:2017年10月30日 11:17:18   作者:旭旭同学  
这篇文章主要介绍了Eclipse中使用Maven创建Java Web工程的实现方式的相关资料,希望通过本文能帮助到大家,让大家实现这样的方式,需要的朋友可以参考下

Eclipse中使用Maven创建Java Web工程的实现方式

1)在Eclipse项目栏中右键单击空白,New(或直接使用Ctrl+N快捷键) —— Other ——Maven Project。

2)选择以webapp模板创建工程

3)填写Group Id 、 Artifact Id 等信息。

groupId

定义了项目属于哪个组,举个例子,如果你的公司是mycom,有一个项目为myapp,那么groupId就应该是com.mycom.myapp.

artifacted

定义了当前maven项目在组中唯一的ID,比如,myapp-util,myapp-domain,myapp-web等。

version

指定了myapp项目的当前版本,SNAPSHOT意为快照,说明该项目还处于开发中,是不稳定的版本。

4)创建完成之后,有的电脑会提示Servelet相关的包没有被导入。这个我们可以统一在POM.XML文件中统一去写。pom.xml里面的依赖可以在http://mvnrepository.com/ 这个网站上去查找,该站点已经帮你把依赖按格式写好,十分方便。下面给出一份我以前做练手项目所用的pom.xml文件。

<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>org.seckill</groupId>
  <artifactId>seckill</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>seckill Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <!-- 使用junit4注解方式 -->
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <!-- 补全项目依赖 -->
    <!-- 1:日志 java日志:slf4,log4j,logback slf4j是 规范、接口 日志实现:log4j、logback -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.12</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
      <version>1.1.1</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.1.1</version>
    </dependency>
    <!-- 实现slf4j接口并整合 -->

    <!-- 2:数据库相关依赖 -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.35</version>
      <scope>runtime</scope>
    </dependency>
    <!-- 数据库连接池 -->
    <dependency>
      <groupId>c3p0</groupId>
      <artifactId>c3p0</artifactId>
      <version>0.9.1.2</version>
    </dependency>

    <!-- DAO框架依赖:MyBatis依赖 -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.3.0</version>
    </dependency>
    <!-- MyBatis自身实现的Spring整合依赖 -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>1.2.3</version>
    </dependency>

    <!-- 3:Servlet Web相关依赖 -->
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>1.1.2</version>
    </dependency>
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.5.4</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>

    <!-- 4:Spring依赖 -->
    <!-- 1)Spring核心依赖 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.1.7.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>4.1.7.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.1.7.RELEASE</version>
    </dependency>
    <!-- 2)Spring dao层 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>4.1.7.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>4.1.7.RELEASE</version>
    </dependency>
    <!-- 3)Spring web依赖 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>4.1.7.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>4.1.7.RELEASE</version>
    </dependency>
    <!-- 4)Spring test相关的依赖 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>4.1.7.RELEASE</version>
    </dependency>
    <!-- redis客户端:Jedis -->
    <dependency>
      <groupId>redis.clients</groupId>
      <artifactId>jedis</artifactId>
      <version>2.7.3</version>
    </dependency>
    <!-- protostuff序列化 -->
    <dependency>
      <groupId>com.dyuproject.protostuff</groupId>
      <artifactId>protostuff-core</artifactId>
      <version>1.0.8</version>
    </dependency>
    <dependency>
      <groupId>com.dyuproject.protostuff</groupId>
      <artifactId>protostuff-runtime</artifactId>
      <version>1.0.8</version>
    </dependency>
    <!-- collections集合框架工具 -->
    <dependency>
      <groupId>commons-collections</groupId>
      <artifactId>commons-collections</artifactId>
      <version>3.2.1</version>
    </dependency>

  </dependencies>
  <build>
    <finalName>seckill</finalName>
  </build>
</project>

5)注意web.xml中要开启标签库和EL表达式支持,要用2.3以上版本,所以把xml头部的都改掉

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
           http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1" metadata-complete="true">

6)maven 项目的src/main/java 和 src/main/resources 都是项目根目录(classpath:)。例如,想访问src/main/resources 目录下的mybatis-config.xml,它的路径参数要写成(“mybatis-config.xml”)。

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关文章

  • Java8时间日期库中的常用使用示例

    Java8时间日期库中的常用使用示例

    这篇文章主要介绍了Java8时间日期库中的20个常用使用示例,帮助大家更好学习Java8是如何处理时间及日期的方法,感兴趣的朋友可以参考一下
    2016-02-02
  • java中的export方法实现导出excel文件

    java中的export方法实现导出excel文件

    这篇文章主要介绍了java中的export方法实现导出excel文件,文章围绕java导出excel文件的相关资料展开详细内容,需要的小伙伴可以参考一下
    2022-03-03
  • java实现简易的学籍管理系统

    java实现简易的学籍管理系统

    这篇文章主要为大家详细介绍了java实现简易的学籍管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-02-02
  • Spring Cloud Gateway去掉url前缀

    Spring Cloud Gateway去掉url前缀

    这篇文章主要介绍了Spring Cloud Gateway去掉url前缀的操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-07-07
  • 浅谈SpringBoot中的Bean初始化方法 @PostConstruct

    浅谈SpringBoot中的Bean初始化方法 @PostConstruct

    这篇文章主要介绍了SpringBoot中的Bean初始化方法 @PostConstruct,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-11-11
  • Spring Retry重试框架的使用讲解

    Spring Retry重试框架的使用讲解

    重试的使用场景比较多,比如调用远程服务时,由于网络或者服务端响应慢导致调用超时,此时可以多重试几次。用定时任务也可以实现重试的效果,但比较麻烦,用Spring Retry的话一个注解搞定所有,感兴趣的可以了解一下
    2022-10-10
  • Java实现几种常见排序算法代码

    Java实现几种常见排序算法代码

    排序(Sorting) 是计算机程序设计中的一种重要操作,它的功能是将一个数据元素(或记录)的任意序列,重新排列成一个关键字有序的序列
    2013-09-09
  • idea导入module全流程

    idea导入module全流程

    这篇文章主要介绍了idea导入module全流程,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-07-07
  • Java中Properties类的操作实例详解

    Java中Properties类的操作实例详解

    这篇文章主要介绍了Java中Properties类的操作实例详解的相关资料,需要的朋友可以参考下
    2017-04-04
  • springboot整合swagger3和knife4j的详细过程

    springboot整合swagger3和knife4j的详细过程

    knife4j的前身是swagger-bootstrap-ui,取名knife4j是希望她能像一把匕首一样小巧,轻量,并且功能强悍,下面这篇文章主要介绍了springboot整合swagger3和knife4j的详细过程,需要的朋友可以参考下
    2022-11-11

最新评论