---
title: "通过Appfuse2来快速建立开发框架(2) - 建立本地开发环境"
author: "bobo"
date: "2007-12-25T23:39:13Z"
tags: []
categories: ["企业架构"]
slug: "appfuse2-2"
draft: false
lastmod: "2007-12-25T23:39:13Z"
id: 150817
url: "https://bobo.iteye.com/blog/150817"
---

通过Appfuse2来快速建立开发框架(2) 
--建立本地开发环境

1、下载
JDK5(jdk5su13) 
Maven 2.0.5+ (maven2.0.8) 
Tomcat 5.5+ (tomcat6.0) 
Eclipse 3.3+ 
MyEclipse 6.0+（可选） 
TortoiseSVN 1.4.5+ 
MySQL GUI Tools 5.0(可选)
 
2、安装
2.1、基本安装
安装前需要确认已安装 winzip 或 winrar 用来解压文件。
安装顺序：TortoiseSVN, JDK，Maven, Tomcat, Eclipse, MyEclipse，MySQL GUI Tools
推荐安装目录：假定根目录为D: (实际可能为D: E: F: 等)

D:/DevEnv 
JDK 
jdk1.5 
Tool 工具包 
Maven-2.0.8 
Eclipse3.3 
MyEclipse6.0 
MySQL GUI Tools 5.0 
TortoriseSVN1.4.5 
Server 服务器 
apache-tomcat-5.5.23 
repository maven本地库 
 
DevEnv Document Projects 不是必须在同一个根目录下  

2.1、Eclipse插件
WTP
参见 Eclipse Web Tools Project 
Spring Support
Spring IDE
参见安装Spring IDE site name=Spring IDE updatesite
url=http://springide.org/updatesite/
更多细节，请参见 http://appfuse.org/display/APF/Eclipse

SVN eclipse plugin
http://subclipse.tigris.org/ Subclipse updatesite
http://subclipse.tigris.org/update_1.2.x
Maven2 插件
http://m2eclipse.codehaus.org/ M2eclipse updatesite
http://m2eclipse.codehaus.org/update/
http://maven.apache.org/eclipse-plugin.html

Eclipse update site URL
http://q4e.googlecode.com/svn/trunk/updatesite/

3、配置
3.1、环境变量设置
DEV_HOME=D:/DevEnv
JAVA_HOME=%DEV_HOME%/JDK/jdk1.5
M2_HOME=%DEV_HOME%/Tool/Maven-2.0.8
CATALINA_HOME=%DEV_HOME%/Server/apache-tomcat-5.5.23
PATH=%JAVA_HOME%/bin;%M2_HOME%/bin;%CATALINA_HOME%/bin;%PATH%
设置好环境变量后在Dos命令行键入"java -version", "mvn -version"确认已安装正确。

3.2、SVN本地配置
设置全局忽略样式 (文件浏览器-〉鼠标右键-〉TortoriseSVN—〉设置-〉常规设置)

target *.jar  *.class  *.log *.bak

3.3、maven2配置
开发通过Maven2来使用统一中心类库，需要修改Maven2的配置
 
修改%M2_HOME%/conf/settings.xml文件

<settings>
        <localRepository>${DEV_HOME}/repository</localRepository>
        <interactiveMode>true</interactiveMode>
	<offline>false</offline>
        <servers>
		<server>
			<id>vs-repo</id>
			<username>vsuser</username>
			<password>veryservice</password>
		</server>
	</servers>
	<mirrors>
		<mirror>
			<id>artifactory</id>
			<mirrorOf>*</mirrorOf>
			<url>http://manage.veryservice.com/artifactory/repo</url>
			<name>Artifactory</name>
		</mirror>
	</mirrors>
	<profiles>
		<profile>
			<id>dev</id>
			<repositories>
				<repository>
					<id>central</id>
					<url>http://xxx.com/artifactory/repo</url>
					<snapshots><enabled>false</enabled></snapshots>
				</repository>
				<repository>
					<id>snapshots</id>
					<url>http://xxx.com/artifactory/repo</url>
					<releases><enabled>false</enabled></releases>
				</repository>
			</repositories>
		</profile>
	</profiles>
	<activeProfiles>
		<activeProfile>dev</activeProfile>
	</activeProfiles>
</settings>
修改${user.home}/.m2/settings.xml文件(C:/Documents and Settings/${user.name}/.m2/settings.xml)

<settings/>

3.4、Eclipse(MyEclipse)配置
设置Eclipse的workspace到D:/Projects（参见安装中设置的工程目录）

mvn -Declipse.workspace=D:\Projects eclipse:add-maven-repo
同时设置Eclipse项目中环境变量 M2_REPO=${DEV_HOME}/repository

4、使用
4.1、新建工程

新建Maven2工程(使用Appfuse2) 
基于Struts2的Web工程 
Web Struts2  mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-struts -DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.1 -DgroupId=com.xxx.web -DartifactId=web  


后台应用工程 
Core(backend)  mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-core -DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.1 -DgroupId=com.xxx.framework -DartifactId=framework  


带struts2的模块工程 
Struts Module  mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-modular-struts -DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.1 -DgroupId=com.xxx.framework -DartifactId=framework  

4.2、maven配置修改 
修改工程目录下pom.xml文件

修改数据库设置：
（更改数据库名、用户名和密码）

<!-- Database settings -->
<jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
<jdbc.url>
<!]>
</jdbc.url>
<jdbc.username>user</jdbc.username>
<jdbc.password>password</jdbc.password>

修改配置支持JPA：
<!--<dao.framework>hibernate</dao.framework>-->
<dao.framework>jpa</dao.framework>
//hibernate3-maven-plugin   如果module方式,则修改core目录下的pom.xml
<\!--<implementation>annotationconfiguration</implementation>-->
<implementation>jpaconfiguration</implementation>

修改代码以及doc包下载方式 根目录下pom.xml
<downloadSources>false</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
 
JPA配置文件在src\main\resources\META-INF\persistence.xml  

4.3 获取Appfuse源代码 
mvn appfuse:full-source

4.4 将Maven2工程转换为Eclipse工程
在项目文件中执行 mvn eclipse:eclipse //
mvn install eclipse:eclipse //module方式
生成Eclipse项目文件

4.5 Eclipse IDE中导入新项目
Eclipse和MyEclipse操作基本相同 
基本框架代码编译
此步骤会生成数据相关的表 mvn test-compile
 hibernate.hbm2ddl.auto=none|validate|create|create-drop|update  

4.6 运行测试新项目
进入项目web目录 执行,如果没有报错,则表示appfuse项目创建成功 mvn jettty:run-war

4.7 core项目设置
右键core 选择properties 点击java build path 选择libraries将maven2 加入的变量去除 

4.8 webapp项目修改
右键webapp选择properties 点击java build path 选择libraries将maven2 加入的变量去除
source下,将webapp/src/main/webapp去除
色sourcre下,添加目录target/
Unknown macro: {项目名称} 
-1.0-SNAPSHOT/WEB-INF/lib,并设置输出路径为src/main/webapp/WEB-INF/lib
在该项目上点右键MyEclipse->Add Web Capabilities->修改Web root地址（点【浏览】按钮指定为当前工作空间下的src/main/webapp文件夹） 

4.9 将webapp上带红点的文件,设置为不检查
在该项目上点右键 properties -> myeclipse -->validation 确保不要将override validation perferences选中.excluded resources 将不检查的文件勾中