1.创建配置Maven Web工程
首先,打开eclipse新建工程,找到Maven project
注意:一定要勾选第一个。
然后next,按下图继续
建好后目录暂时是这个样子
我们稍等一下,建立web项目需要下载一些基础环境
下载完成目录应该如下:
发现pom.xml出错
错误信息为web.xml is missing and is set to true
这时候我们只需要在pop.xml中加入以下代码即可
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
注意:有些人下载后会发现还是少很多文件夹,可以手动添加或者按照如下方式进行创建
不勾,next
选择如下一步一步走即可
然后点击webapp新建JSP
会报错jsp页面提示“Multiple annotations found at this line: - The superclass “javax.servlet.http.HttpServlet” w
执行这一步以后需要将Tomacat运行环境加入就可以将错误搞定
1、右键项目-build path
2、选择configure build path…
3、选择 Java build path
4、Add Library –> server Runtime -> Click Next
5、选择 Server runtime (我的是 Tomcat8.5) –>完成
这样就可以了
2.部署到Tomcat使用
a.我们创建好Jsp,如
然后我们点击pom.xml右键找到run As.
在找到Maven build…一定要找对
然后进行打包命令
然后你就去文件夹找到打包的位置
在哪里看?去控制台
然后我们要将该war包复制到tomcat的webapps文件夹在运行tomacat就可以了
b.另一种方法在Eclipse弄不过该方法不是特别好,在实际开发中war包都是需要打给运维人员进行的。
就是在Pom.xml配置如下代码:
<build>
<finalName>MavenMyProject</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.12</version>
<configuration>
<container>
<!-- 指明使用的tomcat服务器版本 -->
<containerId>tomcat8x</containerId>
<!--指明tomcat服务器的安装目录 -->
<home>E:\Tomcat8.5</home>
</container>
<configuration>
<type>existing</type>
<!--指明tomcat服务器的安装目录 -->
<home>E:\Tomcat8.5</home>
</configuration>
</configuration>
<executions>
<execution>
<id>cargo-run</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
之后更新Maven然后进行run as找到之前的Maven build…一定要找对,这次不是打包,之前打过包了
因为要下载上述插件,所以第一次可能有点慢
然后我们不用启动Tomcat啥的,直接在网页输入
欢迎关注Blog:http://47.107.118.184