在 eclipse galileo jee 中使用 maven 和 tomcat 运行 web 项目
注意, maven 是与 IDE 无关的!!!
也许看到这标题, 就知道贴子一定不好. 因为: 既然选择了 maven, 就说明这个项目与IDE是无关的, 或者说关系是不大的, maven 的定位早已经超过了 IDE 的局限.
都说 maven 和 jetty 配合是最好的, 开放和嵌入式的 jetty 自己不熟, 总是没能成功. 也做为一个摸索, 弄了下在 tomcat 中部署.
说明一下, 第一次使用 maven 的时候要保证网络(周末在家没网, 不过仓库包有一些).
在 eclipse 中部署 tomcat 项目就没必要多说了, 用不习惯的话, 以下的文字可以省掉, 从来都觉得 MyEclipse 是很优秀的! 但破解嘛, 能少用就尽量少用吧. 而且我那 1G 的内存...
下载 maven, 解压至一个自己常用的软件路径, 我喜欢放在 C:\Program Files, 建立环境变量 M2_HOME 并添加至 path (非必需! 喜欢命令行的话是很有必要的.)
在 eclipse 中安装 m2e, 地址 : http://m2eclipse.sonatype.org/sites/m2e
设置 maven 本地仓库: 首先换一个本地仓库路径(团队开发的话, 还需要建一个 nexus 私服, 获取 jar 包的时候先在私服上获取, 没有再去远程获取, 这样可以给团队内部减少带宽)
M2_HOME/conf/settings.xml
<!-- localRepository| The path to the local repository maven will use to store artifacts.|| Default: ~/.m2/repository<localRepository>/path/to/local/repo</localRepository>--><localRepository>d:/repository</localRepository>
-vmC:/Program Files/Java/jdk1.6../jre/bin/client/jvm.dll
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature><nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>2.5.6</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-orm</artifactId><version>2.5.6</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>2.5.6</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>2.5.6</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjrt</artifactId><version>1.6.11</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.6.11</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>2.5.6</version><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.6</version><scope>test</scope></dependency><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-core</artifactId><version>2.1.8</version></dependency><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-json-plugin</artifactId><version>2.1.8</version></dependency><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-junit-plugin</artifactId><version>2.1.8</version></dependency><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-sitemesh-plugin</artifactId><version>2.1.8</version></dependency><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-spring-plugin</artifactId><version>2.1.8</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>3.3.1.GA</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-ehcache</artifactId><version>3.3.1.GA</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-annotations</artifactId><version>3.4.0.GA</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.16</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.4.2</version></dependency><dependency><groupId>c3p0</groupId><artifactId>c3p0</artifactId><version>0.9.1.2</version></dependency><dependency><groupId>opensymphony</groupId><artifactId>sitemesh</artifactId><version>2.4.1</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.16</version></dependency><dependency><groupId>ehcache</groupId><artifactId>ehcache</artifactId><version>1.2.3</version></dependency><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></dependencies>
<build><finalName>example</finalName><sourceDirectory>src/main/java</sourceDirectory><outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory><defaultGoal>install</defaultGoal><resources><resource><targetPath></targetPath><directory>src/main/resources</directory><filtering>true</filtering></resource></resources><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><version>2.0.2</version><configuration><source>1.5</source><target>1.5</target><encoding>UTF-8</encoding></configuration></plugin><plugin><artifactId>maven-resources-plugin</artifactId><configuration><encoding>UTF-8</encoding></configuration></plugin><plugin><artifactId>maven-war-plugin</artifactId><configuration><webappDirectory>src/main/webapp</webappDirectory><warSourceDirectory>target/example-webapp</warSourceDirectory></configuration></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>tomcat-maven-plugin</artifactId></plugin></plugins></build>
<?xml version="1.0" encoding="UTF-8"?><classpath><classpathentry kind="src" output="target/classes" path="src/main/java" /><classpathentry kind="src" output="target/classes" path="src/main/resources"/><classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" /><classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"><attributes><attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/></attributes></classpathentry><classpathentry kind="output" path="target/classes" /></classpath>
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <wb-module deploy-name="example"> <wb-resource deploy-path="/" source-path="/src/main/webapp"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <property name="context-root" value="ex"/> <property name="java-output-path" value="/src/main/webapp/WEB-INF/classes"/> </wb-module></project-modules>