本人有点傻,研究Maven研究了有一段时间,刚刚有些入门,记录下来方便以后使用
工作环境:jdk7 myeclipse10 maven3.1.1
1 下载maven3.1.1
http://maven.apache.org/download.cgi
2配置环境变量
额,别问我为什么叫M2_HOME,事实上我感觉叫MAVEN_HOME更好一点
3 使用myeclipse 新建webproject 并勾选Add Maven support
4 配置maven
点击add 选择maven的文件夹就可以,尽量不要有中文路径
项目建立后 文件夹结构例如以下
MyEclipse不会自己主动建立resources文件夹须要手动建立
以下须要编写 pom.xml
详细须要的东西 能够到 查找
pom.xml例如以下:额 大部分结构抄袭某大神,详细是谁,查的资料太多忘了,仅仅能在此拜谢!
4.0.0 sshmaven sshmaven 0.0.1-SNAPSHOT war UTF-8 org.apache.openejb javaee-api 5.0-1 provided javax.servlet.jsp jsp-api 2.1 provided org.apache.struts struts2-core 2.3.1 org.apache.struts struts2-spring-plugin 2.3.1 org.hibernate hibernate-core 3.6.5.Final commons-dbcp commons-dbcp 1.4 log4j log4j 1.2.16 org.slf4j slf4j-api 1.6.1 org.slf4j slf4j-nop 1.6.4 javassist javassist 3.11.0.GA org.springframework spring-core 3.1.1.RELEASE org.springframework spring-beans 3.1.1.RELEASE org.springframework spring-context 3.1.1.RELEASE org.springframework spring-jdbc 3.1.1.RELEASE org.springframework spring-orm 3.1.1.RELEASE org.springframework spring-web 3.1.1.RELEASE target
默认是该工程的根文件夹。 --> <finalName>mavenwebdemo</finalName><!--生成的目标文件名称 --> <defaultGoal>compile</defaultGoal> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0-beta-1</version> <configuration> <url>http://localhost:8080/manager/text</url> <server>tomcat7</server> <username>admin</username> <password>admin</password> </configuration> </plugin> </plugins> </build> </project>
web.xml的配置
struts.xml配置struts2 org.apache.struts2.dispatcher.FilterDispatcher struts2 /* org.springframework.web.context.ContextLoaderListener contextConfigLocation classpath:spring/applicationContext.xml
applicationContext.xml配置login.html
xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com.my"/> </beans>
UserAction.java
@Controllerpublic class UserAction extends ActionSupport { @Resource private UserService userService; public void test() { System.out.println("hello maven"); userService.test(); }}UserServices.java
@Service("userService")public class UserService { @Resource private UserDao userDao; public void test() { System.out.println("userservice"); userDao.test(); }UserDao.java
@Repositorypublic class UserDao { public void test(){ System.out.println("userdao"); }}直接部署到tomcat6測试
訪问 http://localhost:8080/sshmaven/userAction!test
输出结果
部署
在pom.xml文件点击右键
刷新项目会在target文件夹出现
拷贝进tomcat就可以使用