自从有了云笔记,好久不写博客了。今天写了使用Freemarker静态化JSP页面,索性就发出来。初学,勿喷。html
这篇文字之前放在云笔记里,固然里面有不少借鉴网络上的东西,而本身也使用Maven好久了,索性一块儿发出来。java
3、装好maven插件后,在myeclipse的window-》 preferences窗口的左侧能看到有个maven的选项,以下图web
:apache
咱们须要添加一个外部的maven,也就是本身机器上安装的那个maven,点击installations,选择右边的ADD按钮,选择本身机器安装好的maven,以下图: tomcat
接着点击User Settings,设置user settings,选择%maven_home%\conf\settings.xml;设置local repository为本地仓库,即在settings.xml所设置的路径。以下图:网络
设置好这一步后,在window-->preferences-->java-->build path-->classpath variables找到M2_REPO,edit,编辑path为你的本地仓库(若是已是本地仓库了就不要编辑了)。eclipse
(此处 可能会报出一个错误,如图:maven
1:打开eclipse Click on ‘Window’ -> ‘Preferences’ -> ‘Java’ -> ‘Installed JREs’.ide
If you can’t find any JDK on the list -> click ‘Add’ -> ‘Standard VM’ -> set all paths and click ‘Finish’.ui
After that – check this JDK on the list of installed JREs and click ‘OK’.
2:在eclipse的安装目录中找到eclipse.ini文件编辑这个文件
在-vmargs这个参数的上面添加
-vm
D:\Java\jdk1.5.0_08\bin
两行;有人说JDK不能够用1.7的,我试了没有问题;
)
至此,eclipse+maven的开发环境已经所有搭建好了,开始能够创建项目开发了。
tomcat插件
在pom.xm 加入如下xml。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<path>/wp</path>
<port>8080</port>
<uriEncoding>UTF-8</uriEncoding>
<url>http://localhost:8080/manager/html</url>
<server>tomcat6</server>
</configuration>
</plugin>
简要说明一下:
path 是访问应用的路径
port 是tomcat 的端口号
uriEncoding URL按UTF-8进行编码,这样就解决了中文参数乱码。
Server 指定tomcat名称。
配置就这么简单,基本搞掂,下面看看如何使用。
注: tomcat在启动后,会首先加载本身lib 下的jar ,若是项目中有重复 会报错,可将pom.xml下的相应的dependency 的 scope 改成provided
若是Eclipse 安装了Maven插件,选 择pom.xml文件,击右键——>选择 Run As——> Maven build 。
若是是第一次运行,会弹出下面对话框。在Goals框加加入如下命令: tomcat:run
这样Tomcat 插件就能够运行。
下面介绍几个经常使用的Goal
命令 | 描述 |
tomcat:deploy | 部署一个web war包 |
tomcat:reload | 从新加载web war包 |
tomcat:start |
启动tomcat |
tomcat:stop |
中止tomcat |
tomcat:undeploy |
中止一个war包 |
tomcat:run | 启动嵌入式tomcat ,并运行当前项目 |
两个插件使用方法基本同样,一样须要在pom.xml引用该插件,须要增长如下配置
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>9090</port>
<path>/mgr</path>
<uriEncoding>UTF-8</uriEncoding>
<finalName>mgr</finalName>
<server>tomcat7</server>
</configuration>
</plugin>
具体配置同样。
在这里要注意一下,该插件命名方式有些不一样,好比启动tomcat ,对应的目标命令是: tomcat7:run ,一样,其它命令也是这样,须要更改成:tomcat7:<插件执行点>
maven 错误
eclipse中使用maven插件的时候,运行run as maven build的时候报错
-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
直接的解决方法:使用低版本的maven
能够设一个环境变量M2_HOME指向你的maven安装目录
M2_HOME=D:\Apps\apache-maven-3.3.1
而后在Window->Preference->Java->Installed JREs->Edit
在Default VM arguments中设置
-Dmaven.multiModuleProjectDirectory=$M2_HOME