码迷,mamicode.com
首页 > 其他好文 > 详细

Maven的SSH搭建以及部署

时间:2015-07-01 18:27:50      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:maven   java   ssh   

本人有点傻,研究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

具体需要的东西 可以到 http://mvnrepository.com  查找 

技术分享

技术分享

pom.xml如下:额 大部分结构抄袭某大神,具体是谁,查的资料太多忘了,只能在此拜谢!

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>sshmaven</groupId>
	<artifactId>sshmaven</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<name />
	<description />
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.apache.openejb</groupId>
			<artifactId>javaee-api</artifactId>
			<version>5.0-1</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.1</version>
			<scope>provided</scope>
		</dependency>
		<!-- Struts2 -->
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-core</artifactId>
			<version>2.3.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-spring-plugin</artifactId>
			<version>2.3.1</version>
		</dependency>
		<!-- 添加Hibernate依赖 -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<version>3.6.5.Final</version>
		</dependency>
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.4</version>
		</dependency>             <!-- 添加Log4J依赖 -->
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.16</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-nop</artifactId>
			<version>1.6.4</version>
		</dependency>
		<!-- 添加javassist -->
		<dependency>
			<groupId>javassist</groupId>
			<artifactId>javassist</artifactId>
			<version>3.11.0.GA</version>
		</dependency>
		<!-- 添加Spring依赖 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>3.1.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>3.1.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>3.1.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>3.1.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-orm</artifactId>
			<version>3.1.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>3.1.1.RELEASE</version>
		</dependency>
	</dependencies>

	<build>
		<directory>target</directory><!-- 这是打包的文件的路径。默认是该工程的根目录。 -->
		<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的配置

<span style="white-space:pre">	</span><filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring/applicationContext.xml</param-value>
	</context-param>
struts.xml配置

<span style="white-space:pre">	</span><package name="myuser" namespace="/" extends="struts-default">
		<action name="userAction" class="com.my.user.action.UserAction">
		<result name="login">login.html</result>
		</action>
	</package>
applicationContext.xml配置

<?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

@Controller
public 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

@Repository
public class UserDao {
	
	public void test(){
		System.out.println("userdao");
	}
}

直接部署到tomcat6测试

访问 http://localhost:8080/sshmaven/userAction!test

输出结果

技术分享

部署

在pom.xml文件点击右键

技术分享

技术分享

技术分享

刷新项目会在target目录出现

技术分享技术分享

拷贝进tomcat即可使用


版权声明:本文为博主原创文章,未经博主允许不得转载。

Maven的SSH搭建以及部署

标签:maven   java   ssh   

原文地址:http://blog.csdn.net/lovmf0919/article/details/46710735

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!