eclipse+maven搭建web项目(非常详细)

2023-11-03

一 前言

用maven我们能做什么,有什么好处?

用maven,我们可以方便统一的进行jar包管理,jar包版本升级,快速项目构建以及分模块开发等相关功能。maven使用得好,项目开发速度就会成倍的提升。总之,项目越大,越能体现maven的优势。

二 软件环境

Eclipse JavaEE IDE,版本代号:Mars.2Release (4.5.2)

apache-maven-3.3.9

JDK1.7

apache-tomcat-7.0.29。

三maven安装配置

解压缩apache-maven-3.3.9-bin.tar.gz到本地,如图所示:


配置环境变量(如果你不想脱离开发环境运行项目,此处非必须):


打开conf/settings.xml文件做如下配置

(1)配置本地仓库,如图

(2)配置中央仓库,即配置jar包的下载镜像(建议配置阿里巴巴的镜像,下载速度超快),如图

(3)打开eclipse,设置maven相关参数

首先添加一个本地maven,如图所示:

然后配置UserSettings:

接下来,配置tomcat(通过add按钮去找tomcat的本地安装目录),如图所示


Ok,配置工作就此结束

 

四 Eclipse+Maven创建webapp项目

1、开启eclipse,右键new——》other,如下图找到maven project


2、选择maven project,显示创建maven项目的窗口,勾选如图所示,Create a simple project括号后面的skip archetype selection表示跳过骨架,骨架表示一些创建模板,这里我们不使用模板更加简单。

3、输入maven项目的基本信息,如果是web工程,在Packaging栏我们要选择war,如下图所示:

4、完成maven项目的创建,生成相应的maven项目结果,如下所示:


创建完成之后项目会报错,报错是因为webapp目录下没有web.xml。我们随便从其它web工程里面拷贝WEB-INF目录过来即可,完成后如图:


错误立马消失。

5、接下来拷贝下面这段代码到pom.xml里面,用来确定项目的jdk编译版本:

<build>

       <plugins>

         <plugin>

           <groupId>org.apache.maven.plugins</groupId>

           <artifactId>maven-compiler-plugin</artifactId>

           <version>3.5.1</version>

            <configuration>

             <source>1.7</source>

             <target>1.7</target>

             <encoding>utf-8</encoding>

           </configuration>

         </plugin>

       </plugins>

  </build>

如图所示:

 

这时候,项目又会报错,我们配置完成后,需要执行一次更新项目配置的动作。选中项目 --> 右键 -->Maven --> Update Project(eclipseluna 版本,helios 或indigo 版本选择 Update Project Configuration)。更新完成之后,错误消失,jdk版本也更改过来了,如图所示:


6、在pom.xml中添加jar包依赖

例如添加spring-core,应该是

<dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-core</artifactId>

    <version>3.2.2.RELEASE</version>

</dependency>

不知道写怎么办? 百度搜索maven spring-core repository    然后选择旁边的版本号,如图所示:

点击3.2.2,就可以直接复制出来了

 

附录:spring+springmvc+mybatis整合开发包依赖配置

===========================================================

<dependencies>

    <!--spring3.2.2 start-->

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-core</artifactId>

    <version>3.2.2.RELEASE</version>

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-beans</artifactId>

        <version>3.2.2.RELEASE</version>

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-context</artifactId>

        <version>3.2.2.RELEASE</version>

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-aop</artifactId>

        <version>3.2.2.RELEASE</version>

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-expression</artifactId>

        <version>3.2.2.RELEASE</version>

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-web</artifactId>

        <version>3.2.2.RELEASE</version>

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-webmvc</artifactId>

        <version>3.2.2.RELEASE</version>

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-tx</artifactId>

        <version>3.2.2.RELEASE</version>

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-jdbc</artifactId>

        <version>3.2.2.RELEASE</version>

    </dependency>

    <dependency>

        <groupId>aopalliance</groupId>

        <artifactId>aopalliance</artifactId>

        <version>1.0</version>

    </dependency>

    <dependency>

        <groupId>org.aspectj</groupId>

        <artifactId>aspectjweaver</artifactId>

        <version>1.6.2</version>

    </dependency>

    <!-- spring3.2.2end-->

   

    <!-- 日志包start -->

    <dependency>

        <groupId>org.slf4j</groupId>

        <artifactId>slf4j-api</artifactId>

        <version>1.7.5</version>

    </dependency>

    <dependency>

        <groupId>org.slf4j</groupId>

        <artifactId>slf4j-log4j12</artifactId>

        <version>1.7.5</version>

    </dependency>

    <dependency>

        <groupId>log4j</groupId>

        <artifactId>log4j</artifactId>

        <version>1.2.17</version>

    </dependency>

    <dependency>

        <groupId>commons-logging</groupId>

        <artifactId>commons-logging</artifactId>

        <version>1.1.3</version>

    </dependency>

    <!-- 日志包end -->

   

    <!-- mybatis相关包 start -->

    <dependency>

        <groupId>org.mybatis</groupId>

        <artifactId>mybatis</artifactId>

        <version>3.2.2</version>

    </dependency>

    <dependency>

        <groupId>org.mybatis</groupId>

        <artifactId>mybatis-spring</artifactId>

        <version>1.2.0</version>

    </dependency>

    <dependency>

        <groupId>asm</groupId>

        <artifactId>asm</artifactId>

        <version>3.3.1</version>

    </dependency>

    <dependency>

        <groupId>cglib</groupId>

        <artifactId>cglib</artifactId>

        <version>2.2.2</version>

    </dependency>

    <!-- mybatis相关包 end -->

   

    <!-- mysql连接驱动包 -->

    <dependency>

        <groupId>mysql</groupId>

        <artifactId>mysql-connector-java</artifactId>

        <version>5.1.26</version>

    </dependency>

    <!-- jstl标签库 -->

    <dependency>

        <groupId>jstl</groupId>

        <artifactId>jstl</artifactId>

        <version>1.2</version>

    </dependency>

    <!-- 字节码解析 -->

    <dependency>

        <groupId>org.javassist</groupId>

        <artifactId>javassist</artifactId>

        <version>3.17.1-GA</version>

    </dependency>

    <!-- 阿里巴巴json解析包 -->

    <dependency>

        <groupId>com.alibaba</groupId>

        <artifactId>fastjson</artifactId>

        <version>1.1.15</version>

    </dependency>

    <!-- 阿里巴巴druid连接池 -->

    <dependency>

        <groupId>com.alibaba</groupId>

        <artifactId>druid</artifactId>

        <version>1.0.9</version>

    </dependency>

    <!-- jsp and servlet start -->

    <dependency>

       <groupId>javax.servlet</groupId>

       <artifactId>servlet-api</artifactId>

       <version>2.5</version>

       <scope>provided</scope>

    </dependency>

    <dependency>

       <groupId>javax.servlet.jsp</groupId>

       <artifactId>jsp-api</artifactId>

       <version>2.1</version>

       <scope>provided</scope>

    </dependency>

    <!--jsp and servlet end -->

  </dependencies>

==============================================================

完成如上配置后,maven webapp项目就配置好了。

   

7.编写源代码及配置文件,完成后结构如图所示:

页面代码在下面:

大功告成,接下来启动tomcat运行:右击servers栏,选择Add and Remove…,如图所示:

启动tomcat,没报错就可以在地址栏运行了。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

eclipse+maven搭建web项目(非常详细) 的相关文章

随机推荐

  • Hibernate 总结

    Hibernate Hibernate是什么 Hibernate是一个框架 framework Hibernate是一个orm框架 Orm object relation mapping 对象关系映射 框架 Hibernate处于项目的持久
  • nrf52832--官方例程ble_app_uart添加led特性,实现电脑uart和手机app控制开发板led开和关

    硬件 nrf52832开发板 软件 编译环境 keil SDK版本 nRF5 SDK 17 1 0 ddde560 协议栈版本 s132 nrf52 7 2 0 softdevice 实现功能 在官方串口例程ble app uart的基础上
  • 30多种EMC标准电路分享-接口电路

    目录 01AC24V接口EMC设计标准电路 02AC110V 220VEMC设计标准电路 03AC380V接口EMC设计标准电路 04AV接口EMC设计标准电路 05CAN接口EMC设计标准电路 06DC12V接口EMC设计标准电路 07D
  • 数据库属性映射注解

    Entity 实体注解 Table name cst customer 用来将实体和表建立映射 public class Customer Id GeneratedValue strategy GenerationType IDENTITY
  • JSON处理——FastJson、Jackson、Gson详细使用

    文章目录 一 基本介绍 二 FastJson使用 2 1 对象序列化为JSON字符串 2 2 JSON字符串反序列化为对象 2 3 JSON对象 JSON数组的其他操作 2 4 JSONPath解析JSON 三 Jackson使用 3 1
  • 人工神经网络的拓扑结构,三层神经网络结构图

    人工神经网络的基本组成是什么啊 谷歌人工智能写作项目 小发猫 神经网络BP模型 一 BP模型概述误差逆传播 ErrorBack Propagation 神经网络模型简称为BP Back Propagation 网络模型常见的神经网络结构 P
  • 数据仓库工程师的职业规划

    从2011年3月开始从事数据仓库工作 算起来马上三年了 这三年做过etl工程师 做过模型架构师 做过团队管理 也做过需求分析 数据挖掘 如今又做回etl工程师 只是为了蹲得低点跳的更高 下面谈谈做各个职位的心得 etl工程师 比较简单 技术
  • 解决方法-电脑上打字出现字母分开间隔很大的情况

    电脑语言栏打开微软拼音输入法 按键中模式切换 选中全 半角切换的shift 空格选项 由于全角和半角输入的差异导致的问题 同时按shift 空格键 切换全角 半角符号 即可解决问题
  • 内网穿透工具nps和frp

    nps https github com cnlh nps 免费 nps 的优势在于有一套官方提供的web管理端 service端在云上搭建 ip 8080 登陆service 账号 admin 密码 123 client端搭建在内网机器上
  • Flink Yarn 模式启动 错误问题集锦

    1 Yarn 模式启动找不到类的问题 Caused by java lang ClassNotFoundException javax ws rs ext MessageBodyReader at java net URLClassLoad
  • 前端Ajax之请求

  • 网络协议——七层、五层、四层协议概念及功能

    OSI是一个开放性的通信系统互连参考模型 它是一个定义得非常好的协议规范 OSI模型有7层结构 每层都可以有几个子层 OSI的7层从上到下分别是 7 应用层 6 表示层 5 会话层 4 传输层 3 网络层 2 数据链路层 1 物理层 其中高
  • 知云文献翻译打不开_Xtranslator翻译软件:文献、网页、word,所有翻译阅读统统拿下...

    由于知云只支持PDF格式 有人希望翻译阅读英文网页 WORD 软件的chm格式帮助文件等等 还有些人有自己喜欢的PDF阅读器 比如foxit reader等 使用知云则无法使用自己喜欢的PDF阅读器了 还有些高频使用PDF注释功能的人不习惯
  • VS开发Linux程序(VisualGDB)

    点击打开链接 VisualGDB是在vs上开发Linux程序的工具 利用visual studio强大的功能调试Linux程序真的是很惬意的一件事情 VisualGDB支持Linux的原理是 通过ssh连接到Linux系统上通过ssh给li
  • shell脚本进阶1——精读ansible+shell脚本

    文章目录 一 脚本规划思路 二 主控机shell脚本 2 1 脚本输出字体特效 2 2 生成菜单栏对话框 2 3 配置本地yum源仓库 2 4 配置受控机yum源 2 5 关闭防火墙和selinux 2 6 把docker安装包给受控机 2
  • MATLAB安装MinGW编译器

    第一步 打开matlab主页里附加功能的获取附加功能 第二步 搜索MinGW 接着选择第一个选项 第三步 点击下载 将下载的文件放在安装matlab的一级文件夹下 打开matlab找到该文件 双击安装 如果你安装成功 恭喜你 但一般都会出现
  • Okhttp关于 java.lang.NoSuchMethodError: okio.BufferedSource报错

    我们可以从报错的内容来下手 NoSuchMethod 就是说okio并没有其中的方法 我找了很久才恍然大悟 这都说出来了还傻呵呵的找解决办法 我用的okio 1 7 0很明显这个版本早就过时了 当我换成okio1 9 0问题迎刃而解 哎 浪
  • 谈高考志愿填报

    目录 不如先说说我自己 一 选专业还是选学校 二 你想推荐 避雷的专业 三 填报志愿的策略 四 影响专业选择的因素 各省高考成绩已出 又到一年高考季 张雪峰提到 普通家庭不要光谈理想 也要谈落地 志愿怎样填报 选专业还是选学校 什么专业好就
  • 贝叶斯优化

    贝叶斯优化 BO RF贝叶斯优化随机森林多输入单输出回归预测 Matlab完整程序 目录 贝叶斯优化 BO RF贝叶斯优化随机森林多输入单输出回归预测 Matlab完整程序 预测结果 基本介绍 评价指标 程序设计 参考资料 预测结果 基本介
  • eclipse+maven搭建web项目(非常详细)

    一 前言 用maven我们能做什么 有什么好处 用maven 我们可以方便统一的进行jar包管理 jar包版本升级 快速项目构建以及分模块开发等相关功能 maven使用得好 项目开发速度就会成倍的提升 总之 项目越大 越能体现maven的优