maven工程下整合spring+mybatis+freemarker

标签: maven 工程 spring | 发表时间:2013-11-27 06:59 | 作者:zhengyinhui100
出处:http://blog.csdn.net

博客地址:http://zhengyinhui.com/?p=142


由于工作主要是前端开发,做后端的项目比较少,最近自己做个项目,发觉好多的都忘了,这里写篇博客整理下maven工程下整合spring+mybatis+freemarker相关内容。

新建个Archetype为maven-archetype-webapp的maven项目(安装maven插件:http://download.eclipse.org/technology/m2e/releases),在pom文件添加相关依赖:

<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.my.sport</groupId>
	<artifactId>sport-web</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>sport-web Maven Webapp</name>
	<url>http://maven.apache.org</url>

	<properties>
		<spring.version>3.1.2.RELEASE</spring.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>3.0-alpha-1</version>
			<scope>provided</scope>
		</dependency>
		<!-- dbcp connection pool -->
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.4</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.21</version>
		</dependency>
		<dependency>
			<groupId>org.freemarker</groupId>
			<artifactId>freemarker</artifactId>
			<version>2.3.16</version>
		</dependency>
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>2.2.2</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.2.3</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.2.1</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.10</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>net.sf.json-lib</groupId>
			<artifactId>json-lib</artifactId>
			<version>2.2.3</version>
		</dependency>
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.4</version>
		</dependency>
		<dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-core</artifactId>  
            <version>${spring.version}</version>  
        </dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-asm</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aspects</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-expression</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jms</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-orm</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-oxm</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${spring.version}</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
	</dependencies>

	<build>
		<finalName>sport-web</finalName>
		<defaultGoal>install</defaultGoal>
		<plugins>
			<!-- 忽略编译项目时的测试运行 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<skip>true</skip>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

新建source folder:src/main/resource,新建一个mysql的属性文本src/main/resource/prop/mysql.properties:

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/sport
jdbc.username=root
jdbc.password=123456

新建spring配置文件src/main/resource/applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-3.1.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

    <context:property-placeholder location="classpath:prop/mysql.properties" />
    
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	</bean>

	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
    
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="configLocation" value="classpath:mybatis-config.xml" />
		<property name="dataSource" ref="dataSource" />
		<!-- 映射文件集合 -->
		<property name="mapperLocations" value="classpath:com/sport/mapper/*.xml" />
	</bean>
	
</beans>
新建mybatis的配置文件src/main/resources/mybatis-config.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <!-- 配置mybatis的缓存,延迟加载等等一系列属性 -->  
    <settings>  
        <!-- 全局映射器启用缓存 -->  
        <setting name="cacheEnabled" value="true" />  
        <!-- 查询时,关闭关联对象即时加载以提高性能 -->  
        <setting name="lazyLoadingEnabled" value="true" />  
        <!-- 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指 定),不会加载关联表的所有字段,以提高性能 -->  
        <setting name="aggressiveLazyLoading" value="false" />  
        <!-- 对于未知的SQL查询,允许返回不同的结果集以达到通用的效果 -->  
        <setting name="multipleResultSetsEnabled" value="true" />  
        <!-- 允许使用列标签代替列名 -->  
        <setting name="useColumnLabel" value="true" />  
        <!-- 允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值),数据表的PK生成策略将被覆盖 -->  
        <!-- <setting name="useGeneratedKeys" value="true" /> -->  
        <!-- 给予被嵌套的resultMap以字段-属性的映射支持 -->  
        <setting name="autoMappingBehavior" value="FULL" />  
        <!-- 对于批量更新操作缓存SQL以提高性能 -->  
        <setting name="defaultExecutorType" value="BATCH" />  
        <!-- 数据库超过25000秒仍未响应则超时 -->  
        <setting name="defaultStatementTimeout" value="25000" />  
    </settings>
    <!-- 全局别名设置,在映射文件中只需写别名,而不必写出整个类路径 -->  
    <typeAliases>  
        <typeAlias alias="UserLoginEntity"  
            type="com.sport.entity.UserLoginEntity" />  
    </typeAliases>
    <!-- 非注解的sql映射文件配置,如果使用mybatis注解,该mapper无需配置,但是如果mybatis注解中包含@resultMap注解,则mapper必须配置,给resultMap注解使用 -->  
	<!-- 因为如果user-mapper.xml与namespace的接口在同一路径下,就不需要在mybaits.xml中再进行配置了。 
	<mappers>
		<mapper resource="com/sport/mapper/UserLoginMapper.xml" />
	</mappers>
	-->
</configuration>
新建spring的dispatcher配置文件src/main/resources/dispatcher-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-3.1.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

	<!-- 注解支持 -->
	<mvc:annotation-driven />

	<!-- 使用注解方式的事务 -->
	<tx:annotation-driven transaction-manager="transactionManager" />
	
	<!-- 对包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
	<context:component-scan base-package="com.sport" />
	
	<!-- 自动扫描dao -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="annotationClass" value="org.springframework.stereotype.Repository" />
		<property name="basePackage" value="com.sport.dao" />
		<property name="sqlSessionFactory" ref="sqlSessionFactory" />
	</bean>
	
	<!--  bean方式配置dao
	<bean id="userLoginDao" class="org.mybatis.spring.mapper.MapperFactoryBean">  
       <property name="mapperInterface"  value="com.sport.dao.IUserLoginDao" />  
       <property name="sqlSessionFactory" ref="sqlSessionFactory" />  
    </bean>
    -->

</beans>

修改web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	                         http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
	     version="2.5" >
	     
    <display-name>sport-web</display-name>
	
	<!-- 区分项目名称,防止默认重名 -->
	<context-param>
		<param-name>webAppRootKey</param-name>
		<param-value>sport-web</param-value>
	</context-param>
	
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			classpath:applicationContext.xml
		</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!-- 字符集 过滤器  -->
	<filter>
		<filter-name>CharacterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>CharacterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- Spring view分发器 -->
	<servlet>
		<servlet-name>dispatcher</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:dispatcher-servlet.xml</param-value>
		</init-param>
		<load-on-startup>0</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>dispatcher</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	
	<welcome-file-list>
		<welcome-file>/views/index.ftl</welcome-file>
	</welcome-file-list>

	<error-page>
		<error-code>404</error-code>
		<location>/html/404.html</location>
	</error-page>

</web-app>


创建mysql示例数据库sport:

-- ----------------------------
--  Table structure for `user_login`
-- ----------------------------
DROP TABLE IF EXISTS `user_login`;
CREATE TABLE `user_login` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(50) NOT NULL,
  `password` varchar(100) NOT NULL,
  `email` varchar(100) NOT NULL,
  PRIMARY KEY (`user_id`,`email`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
--  Records of `user_login`
-- ----------------------------
BEGIN;
INSERT INTO `user_login` VALUES ('1', 'ee', '111111111', '[email protected]'), ('2', 'ww', '33333', '[email protected]');
COMMIT;
新建实体类UserLoginEntity.java:

package com.sport.entity;

import java.io.Serializable;

public class UserLoginEntity implements Serializable{
	
	private static final long serialVersionUID = 1L;
	private int userId;
	private String userName;
	private String email;
	private String password;
	
	public int getUserId() {
		return userId;
	}
	public void setUserId(int userId) {
		this.userId = userId;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	
	
}
新建dao接口IUserLoginDao.java:

package com.sport.dao;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.sport.entity.UserLoginEntity;

@Repository
@Transactional
public interface IUserLoginDao {

	public UserLoginEntity getUserLogin(int userId);

}
新建对应的mybatis配置文件com.sport.mapper/UserLoginMapper.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 这里的namespace名字必须为执行该sql的dao地址 -->
<mapper namespace="com.sport.dao.IUserLoginDao">
	
	<resultMap type="UserLoginEntity" id="userLoginResultMap">  
        <id property="userId" column="user_id"/>  
        <result property="password" column="password"/>  
        <result property="userName" column="user_name"/>  
        <result property="email" column="eamil"/>
    </resultMap>
     
	<select id="getUserLogin" parameterType="String" resultType="UserLoginEntity" resultMap="userLoginResultMap">  
        <![CDATA[ 
            select * from user_login where user_id =  #{userId}
        ]]>   
    </select>
    
</mapper>

再新建简单的service接口IUserLoginService.java:

package com.sport.service;

import com.sport.entity.UserLoginEntity;

public interface IUserLoginService {

	public UserLoginEntity checkLogin(int userId);
	
}

UserLoginServiceImpl.java:

package com.sport.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sport.dao.IUserLoginDao;
import com.sport.entity.UserLoginEntity;
import com.sport.service.IUserLoginService;

@Service("userLoginService")
public class UserLoginServiceImpl implements IUserLoginService {
	
	@Autowired
	private IUserLoginDao userLoginDao;

	public UserLoginEntity checkLogin(int userId) {
		UserLoginEntity userLogin= userLoginDao.getUserLogin(userId);
		return userLogin;
	}
	
	

}

新建controller类UserLogin.java:

package com.sport.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.sport.entity.UserLoginEntity;
import com.sport.service.IUserLoginService;


@Controller
@RequestMapping("userLogin")
public class UserLogin {
	
	@Autowired
	private IUserLoginService userLoginService;

	@RequestMapping("test.do")
	public ModelAndView test(){
		ModelAndView m=new ModelAndView(); 
		UserLoginEntity userLoginEntity=userLoginService.checkLogin(1);
		m.addObject("result", userLoginEntity);
		m.setViewName("test");
		return m;
	}
	
}

整合freemarker,新建配置文件src/main/resources/freemarker.properties:

tag_syntax=auto_detect
template_update_delay=2
default_encoding=UTF-8
output_encoding=UTF-8
locale=zh_CN
date_format=yyyy-MM-dd
time_format=HH:mm:ss
datetime_format=yyyy-MM-dd HH:mm:ss

在src/main/resources/dispatcher-servlet.xml中加入freemarker配置:

        <!-- 设置freeMarker的配置文件路径 -->
	<bean id="freemarkerConfiguration"
		class="org.springframework.beans.factory.config.PropertiesFactoryBean">
		<property name="location" value="classpath:prop/freemarker.properties" />
	</bean>

	<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape" />

	<!-- 配置freeMarker的模板路径 -->
	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<property name="templateLoaderPath">
			<value>/WEB-INF/views/</value>
		</property>
		<property name="freemarkerVariables">
			<map>
				<entry key="xml_escape" value-ref="fmXmlEscape" />
			</map>
		</property>
	</bean>


	<!-- 配置freeMarker视图解析器 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
		<property name="contentType" value="text/html; charset=utf-8" />
		<property name="cache" value="true" />
		<property name="prefix" value="" />
		<property name="suffix" value=".ftl" />
		<property name="exposeSpringMacroHelpers" value="true"></property>
		<property name="exposeRequestAttributes" value="true"></property>
	</bean>

新建测试页面src/main/webapp/WEB-INF/views/test.ftl:

<html>  
<head>  
<title>test</title>
</head>
<body>
test:userId:${result.userId};userName:${result.userName};email:${result.email};
</body>
</html>

启动jetty服务器(runjettyrun插件:http://run-jetty-run.googlecode.com/svn/trunk/updatesite),浏览器输入http://localhost:8080/sport-web/userLogin/test.do可以看到如下结果:

test:userId:1;userName:ee;email:[email protected];




作者:zhengyinhui100 发表于2013-11-26 22:59:39 原文链接
阅读:104 评论:0 查看评论

相关 [maven 工程 spring] 推荐:

maven工程下整合spring+mybatis+freemarker

- - CSDN博客架构设计推荐文章
博客地址:http://zhengyinhui.com/?p=142. 由于工作主要是前端开发,做后端的项目比较少,最近自己做个项目,发觉好多的都忘了,这里写篇博客整理下maven工程下整合spring+mybatis+freemarker相关内容. 新建个Archetype为maven-archetype-webapp的maven项目(安装maven插件:http://download.eclipse.org/technology/m2e/releases),在pom文件添加相关依赖:.

使用maven一步一步构建spring mvc项目

- - CSDN博客架构设计推荐文章
1      使用eclipse构建maven web项目. 1.1新建Maven的web项目. 打开菜单File –New-MavenProject. 选择模板类型archtype——maven-archtype-webapp. 输入Group Id和artifact Id. Group Id一般填入项目名称,Artifact Id一般填入子项目的名称.

eclispe中对maven工程进行本地debug

- - ITeye博客
1、在eclipse安装了m2eclipse插件,并在工程的pom.xml中配置好maven-tomcat-plugin后,单击Eclipse菜单“Run”中的“Run Configurations”. 2、在弹出的对话框中的左侧树中找“到Maven Build”,在其上点击右键并单击“New”. 3、在右侧的“Name”一栏填入自定义的名称.

maven学习之maven与eclipse集成

- - ITeye博客
    在上一篇博文中讲到了maven的配置,今天要讲maven与eclipse的集成. 现在在java开发中,eclipse占据了绝大部分的市场份额. 其他的关于NetBeans,IDEA中的关于maven的配置,读者可参阅相关资料. (注:关于IDEA,据说是款非常强大的集成开发环境,但是据说对svn的支持不是很好,道听途说而已).

Maven最佳实践:划分模块

- - 企业架构 - ITeye博客
“分天下为三十六郡,郡置守,尉,监” —— 《史记·秦始皇本纪》. 所有用Maven管理的真实的项目都应该是分模块的,每个模块都对应着一个pom.xml. 它们之间通过继承和聚合(也称作多模块,multi- module)相互关联. 我们明明在开发一个项目,划分模块后,导入Eclipse变成了N个项目,这会带来复杂度,给开发带来 不便.

从Maven仓库中导出jar包

- - 企业架构 - ITeye博客
从Maven仓库中导出jar包:进入工程pom.xml 所在的目录下,. 输入以下命令:mvn dependency:copy-dependencies -DoutputDirectory=lib. 更简单的  mvn dependency:copy-dependencies    会导出到target\dependency 下面.

Maven 3 入门 -- 核心概念

- - 开源软件 - ITeye博客
例如上篇helloworld的pom.xml配置文件中的. 其实就是坐标,那么Maven的坐标元素包括groupId、artifactId、version、packaging、classifier. 当一个项目通过依赖,插件或者父项目引用与另外一个项目关联的时候,Maven通过坐标来精确定位一个项目.

简单的Maven模块结构

- - 研发管理 - ITeye博客
简单的Maven模块结构是这样的:. 上述简单示意图中,有一个父项目(app-parent)聚合很多子项目(app-util, app-dao, app-service, app-web). 每个项目,不管是父子,都含有一个pom.xml文件. 而且要注意的是,小括号中标出了每个项目的打包类型. 父项目是pom,也只能是pom.

maven导出项目依赖的jar包

- - 互联网 - ITeye博客
在进行项目部署时,需要将maven项目所依赖的jar导出到指定目录,本文讲解如何导出项目依赖的jar包. 一、导出到默认目录 targed/dependency .     从Maven项目中导出项目依赖的jar包:进入工程pom.xml 所在的目录下,执行如下命令:.        或在eclipse中,选择项目的pom.xml文件,点击右键菜单中的Run As,见下图红框中,在弹出的Configuration窗口中,输入  dependency:copy-dependencies 后,点击运行.

Maven使用archetype生成项目

- -
Archtype指项目的骨架, Maven中的 maven-archetype-plugin插件使用户可以方便的生成所需的项目骨架.. ###1.命令行调用maven插件. 如果不加任何参数,命令窗口显示的会有上千中项目骨架可够选择,我们可以使用 -DarchetypeCatalog, -Dfilter选择过滤项目骨架,参数赋值的格式跟JAVA设置系统属性一样 -D=.