eclipse maven web project
what's the Maven?
Maven是一个项目管理工具,包含一个项目对象模型( POM: Project Object Moudel) , 一组标准集合,一个项目生命周期(Project Lifecycle) , 一个依赖管理系统(Dependency Management) , 和用来运行定义再生命周期阶段(phase)中插件(plugin)目标(goal) 的逻辑定义
Maven is a project management of tool , include a Project Object Moudel , a group stanard collection , a Project Lifecycle, a Dependency Management , and ....
Maven 可以通过修改pom.xml文件添加jar包,jar包回自动地从Maven仓库中下载(可以自己创建本地私服)
Maven can add jar by writing pom.xml, jar will be dowload automatically from https://mvnrepository.com/such as:
in dependencies
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.2.0</version> </dependency>
Maven 可以打包项目为 war包和jar包
Maven can pack war or jar
war包是一个web项目, 它通过Tomcat自动运行,只要放入webapps文件夹中,Tomcat会自动解压文件
war pack is web project , it can be run only putting in under webapps by Tomcat
jar包是一个已经写好的类,然后打包, 可以放入项目中,像 lib 文件
jar pack is already written class and packed , can put in your project, such as in lib file
一,创建新的Maven Web 项目
New Maven Web Project
Ctrl + N
选择Maven Project
select Maven Project
Select project name and location
select Archetype
Group Id : org.apache.maven.archetypes
Artiface Id : maven-archetype-webapp
Version : 1.4
url : https://repo1.maven.org/maven2
二,将Web 项目导为WAR包
Export a Web Project into an external WAR file
由于默认Eclipse是javaSE , 所以需要下载Web相关software
help -> Install New Software
select Web, XML , JavaEE and OSGi Enterprise Development
Then downloding
之后就会在Properties中出现project facets属性
select current project (right click) -> Properties -> project facets
select Dynamic Web Moudle
现在,就可以将web项目打包成war文件,war文件可以直接放在Tomcat 的webapps中,由Tomcat自动解压运行
Now , We can export a Web Moudule into an external WAR file
三,需要一个本地Tomcat环境,可以再eclipse内运行
Need a local Tomcat Envirmont , running in eclipse
首先,下载Eclipse Tomcat Plugin 插件, 不然 window->Preference 中没有Tomcat
First , downloading Eclipse Tomcat Plugin , otherwise window-> Preferenct never Tomcat
位于help -> Eclipse Maketplace , 搜索 Tomcat, 选择Eclipse Tomcat Plugin 9.1.4
在window -> preference 中, 选择server-> Runtime Environment, 添加
等待下载完后,click Finish 结束
上面是下载和配置添加tomcat
给项目配置Build Path, 这才是让项目拥有Tomcat 运行环境
选择tomcat 9运行
或者选择服务器运行,choose an existing server -> Finish
注: 后面我改为用Tomcat 9,原因是Tomcat 10 的sevlet-api.jar包里面不是javax而是jakata, 因为javax被oracle捐赠给了apache基金会,这就导致原本的项目变成了Jakarta开头的包。导致jsp代码一直报 the superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path , 寻数果,无解,降为Tocmat9
war pack is web projec