您的位置:首页 > 移动开发

Eclipse中开发Appfuse2.0项目

2012-08-15 17:03 357 查看
一、在Eclipse中导入Appfuse2.0项目

1.生成Eclipse项目文件

使用命令行,在项目目录下,执行mvn eclipse:eclipse。成功执行后,将生成eclipse所需项目文件(.project、.classpath、.setting)。如果你使用的archetype是modular,需使用mvn install eclipse:eclipse命令。

当我在执行mvn eclipse:eclipse时,发生下面的错误:

D:\appfuse2\myproject>mvn eclipse:eclipse

[INFO] Scanning for projects...

[INFO] ------------------------------------------------------------------------

[INFO] Building AppFuse Spring MVC Application

[INFO]    task-segment: [eclipse:eclipse]

[INFO] ------------------------------------------------------------------------

[INFO] Preparing eclipse:eclipse

[INFO] [aspectj:compile {execution: default}]

[INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}]

[INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}]

[INFO] [eclipse:eclipse {execution: default-cli}]

[INFO] Adding support for WTP version 1.5.

[INFO] Using Eclipse Workspace: null

[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAIN

ER

[INFO] Unable to read jar manifest from d:\m2\repository\org\appfuse\appfuse-web

\2.1.0-M1\appfuse-web-2.1.0-M1.pom

[INFO] Resource directory's path matches an existing source directory. Resources

will be merged with the source directory src/main/resources

[INFO] ------------------------------------------------------------------------

[ERROR] BUILD ERROR

[INFO] ------------------------------------------------------------------------

[INFO] Request to merge when 'filtering' is not identical. Original=resource src

/main/resources: output=target/classes, include=[], exclude=[ApplicationResource

s_de.properties|ApplicationResources_fr.properties|ApplicationResources_ko.prope

rties|ApplicationResources_nl.properties|ApplicationResources_no.properties|Appl

icationResources_pt*.properties|ApplicationResources_tr.properties|ApplicationRe

sources_zh*.properties|applicationContext-resources.xml|**/*.java], test=false,

filtering=true, merging with=resource src/main/resources: output=target/classes,

include=[applicationContext-resources.xml], exclude=[**/*.java], test=false, fi

ltering=false

[INFO] ------------------------------------------------------------------------

[INFO] For more information, run Maven with the -e switch

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 33 seconds

[INFO] Finished at: Wed Apr 07 16:51:57 GMT+08:00 2010

[INFO] Final Memory: 29M/51M

[INFO] ------------------------------------------------------------------------

后来在http://n4.nabble.com/mvn-eclipse-eclipse-td961299.html中找到了Matt给出解决的方法,将maven-eclipse-plugin的改为2.5.1。

编辑修改项目的pom.xml,修改maven-eclipse-plugin版本,如下:

<artifactId>maven-eclipse-plugin</artifactId>

<version>2.5.1</version>

 
 
2.导入到Eclipse

开启eclipse,在菜单File > Import > General:Existing Projects into Workspace,选择你项目所在目录,点击Finish完成项目的导入。



二、在Eclipse配置Maven环境

为了方便我们在Eclipse进行项目开发,不用每次使用Maven的时候都要切换到命令行,还需要配置一下Eclipse中Maven环境。

1.配置Local Repositories

下面两种选其一即可:

a.在系统环境变量中,增加M2_REPO=D:\m2\repository

b.Eclipse中设置ClassPath,在选择菜单中Windows->Preferences->Java->Build Path->Classpath Variables中设置M2_REPO

2.安装Maven的Eclipse插件

首先安装m2eclipse(一个Maven的Eclipse插件),在菜单Help->Install New Software,输入http://m2eclipse.sonatype.org/sites/m2e,根据提示完成插件安装。

3.整合依赖关系管理

在成功安装m2eclipse后,在项目上右键,选择弹出式菜单Maven->Enable Dependency Management,这样做的目的主要是为了将Maven pom中关于项目的依赖关系与Eclipse中的Classpath整合。



4.在Eclipse中将Maven作为外部工具调用

我们经常需要从eclipse执行一些maven goals,这可以通过配置外部工具实现。

为Eclipse添加一个变量,指向本地maven的可执行文件(mvn.bat/mvn)。从菜单栏,选择Window->Preferences,选择Run/Debug->String Substitution



增加一个新的变量,比如maven_exec



新增外部工具配置。在菜单栏中,选择Run->External Tools->External Tools Configurations,选择New Program,在Location中使用刚才定义的${maven_exec}。在Working Directory中引用${project_log}变量作为工作目录,在Arguments指定相应的maven goals作为参数,也可已指定${string_prompt}。



添加你常用的goal,如下图:



如果在Arguments中包含${string_prompt}变量,在执行外部工具时,会先弹出一个输入框,输入特定参数即可。这样我们就可以通过这种方式执行不常用的goal,或者需要指定参数的goal。



原文:http://lu2002lulu.iteye.com/blog/315133
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息