[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[整理]使用Ant调用PDE自动Build RCP Application。

上一篇:[整理]Byte Order 字节顺:BIG-ENDIAN 和 LITTLE-ENDIAN
下一篇:[整理]串口通信,丢失0x00数据

添加日期:2011/2/24 16:21:46 快速返回   返回列表 阅读8352次
下载jar包的网址
http://download.eclipse.org/eclipse/downloads/drops/R-3.6.1-201009090800/ 

一个热帖
http://www.modumind.com/2007/06/06/getting-started-with-pde-build/

一个教程
http://www.eclipse.org/articles/Article-PDE-Automation/automation.html
=======================================================
过程:
1.建立RCP工程
2.plugin.xml的依赖项,根据需要添加jar包,缺啥加啥。
2.生成.product文件,配置,添加依赖的包(包括自己),add required,缺啥加啥,等等
3.复制buildRCP.xml和build.properties,修改名字什么的。

========================================================
看下目录结构:
-----------------------------
│  run_MainFrame.bat

├─buildEnv
│  ├─ant
│  ├─eclipse
│  ├─jdk1.6.0_17
│  └─RCP-build-require
│      └─target
├─buildResult
│  ├─HelloWorld
│  └─mainframe
└─projectHome
    ├─HelloWolrd
    │      build.properties
    │      buildRCP.xml
    └─mainframe
            build.properties
            buildRCP.xml
-----------------------------
ant,就是ant的目录了。
eclipse(大Eclipse目录,平时使用的Eclipse目录,复制一个过来。
    不过,这个Eclipse是做插件开发的,应该jar包多一些吧。
    PDE Build需要使用完整的Eclipse SDK。光有几个jar包是不行的。)
RCP-build-require/target/ 放RCP Delta Pack和RCP Runtime Binary,
    把eclipse-3.6.1-delta-pack.zip和org.eclipse.rcp-3.6.1.zip解压到这里,
    后者要放到前者解压出来的eclipse目录下再解压。
    target这个目录是指你的目标平台环境,
    最好只有RCP Runtime + RCP Delta + GEF等 + 必要的一些jar包,总之越少越好吧。
    目标平台的RCP版本可以与Eclipse IDE的RCP版本不同。
buildResul,build结果所在目录,下面的目录是自动生成的
projectHome,工程目录,从Eclipse的workspace下直接把工程复制过来。
=======================================================
看一下各个文件内容:
run_MainFrame.bat



rem ---------工程名(即projectHome目录下该工程的名字),修改即可,后面不要多空格-------------
set PROJECT_NAME=mainframe


rem -----------------以下不用修改----------------------------
@ECHO on

rem 取得当前路径
set CURRENT_DIR=%CD%

rem 设置各种路径
set ANT_HOME=%CURRENT_DIR%\buildEnv\ant
set JAVA_HOME=%CURRENT_DIR%\buildEnv\jdk1.6.0_17
set PROJECT_HOME=%CURRENT_DIR%\projectHome\%PROJECT_NAME%
set ECLIPSE_PATH=%CURRENT_DIR%/buildEnv/eclipse
set OUTPUT_PATH=%CURRENT_DIR%/buildResult/%PROJECT_NAME%
set BASE_PATH=%CURRENT_DIR%/buildEnv/RCP-build-require

rem 应该把共通参数提出来,放common.properties里,放到打包程序这里。build时先copy进去
rem 这样,每个工程只设置自己相关的参数。

rem 执行build
call %ANT_HOME%\bin\ant.bat -f %PROJECT_HOME%\buildRCP.xml -DeclipseLocation=%ECLIPSE_PATH% -DbuildDirectory=%OUTPUT_PATH% -Dbase=%BASE_PATH%

echo -------------------------脚本执行完毕-------------------------
pause



buildRCP.xml:

<project name="mainframe" default="build">
    <property file="build.properties" />

    <target name="init">
        <mkdir dir="${buildDirectory}" />
        <mkdir dir="${buildDirectory}/plugins" />
        <mkdir dir="${buildDirectory}/features" />
        <copy todir="${buildDirectory}/plugins">
            <fileset dir="../">
                <include name="${rcp.plugin}/**" />
            </fileset>
        </copy>
        <copy todir="${buildDirectory}/features">
            <fileset dir="../">
                <include name="${feature.plugin}/**" />
            </fileset>
        </copy>
    </target>

    <target name="pde-build">
        <java classname="org.eclipse.equinox.launcher.Main" fork="true" failonerror="true">
        <arg value="-application" />
        <arg value="org.eclipse.ant.core.antRunner" />
        <arg value="-buildfile" />
        <arg value="${eclipseLocation}/plugins/org.eclipse.pde.build_${pdeBuildPluginVersion}/scripts/productBuild/productBuild.xml" />
        <arg value="-Dtimestamp=${timestamp}" />
        <arg value="-DbuildDirectory=${buildDirectory}" />
        <arg value="-DeclipseLocation=${eclipseLocation}" />
        <arg value="-Dbase=${base}" />
        <arg value="-DbaseLocation=${baseLocation}" />
        <arg value="-DcompilerArg=${compilerArg}" />
        <!-- 需要的属性变量需要用-D方式传进去,否则命令行过来的值不认。 -->

        <classpath>
            <pathelement location="${eclipseLocation}/plugins/org.eclipse.equinox.launcher_${equinoxLauncherPluginVersion}.jar" />
        </classpath>
        </java>
    </target>

    <target name="clean">
        <delete dir="${buildDirectory}" />
    </target>

    <target name="build" depends="clean,init, pde-build" />

</project>



build.properties,里面关于路径的字段不用修改的,就改改名字啥的就可以了。

source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
               META-INF/,\
               .,\
               icons/,\
               about.gif,\
               splash1.bmp,\
               lib/xxx.jar,\
               introContent.xml,\
               script/,\
               splash.bmp,\
               template/,\
               content/
jars.extra.classpath = lib/xxx.jar
##########################################################
# Copyright (c) 2003, 2006 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#     IBM Corporation – initial API and implementation
##########################################################
# Parameters describing how and where to execute the build.
# Typical users need only update the following properties:
#    baseLocation – where things you are building against are installed
#    bootclasspath – The base jars to compile against (typicaly rt.jar)
#    configs – the list of {os, ws, arch} configurations to build.
#
# Of course any of the settings here can be overridden by spec’ing
# them on the command line (e.g., -DbaseLocation=d:/eclipse

############# PLUG-IN VERSIONS ######################

#Plug-in的工程名
rcp.plugin=mainframe

#Feature的工程名,因为没有Feature,就随便写了个名字
feature.plugin=mainframe.feature

# PDE Build的版本
# 实际就是plugins目录下有个类似org.eclipse.pde.build_3.6.1.R36x_v20100823\的文件夹
# 要后面那堆数字什么的。
pdeBuildPluginVersion=3.6.1.R36x_v20100823

# equinox.launcher的版本
# 同上,plugins目录下有个org.eclipse.equinox.launcher_1.1.0.v20100507.jar文件
equinoxLauncherPluginVersion=1.1.0.v20100507

############# BASE LOCATION #########################
# 目标平台的Base目录,外部传入绝对路径
base=

############# ECLIPSE LOCATION ######################
# Eclipse 安装目录,以调用PDE.
#eclipse的路径用相对路径,不好使,所以从命令行传入绝对路径。
eclipseLocation=

############# PRODUCT/PACKAGING CONTROL #############
product=/mainframe/mainframe.product
runPackager=true

#Set the name of the archive that will result from the product build.
#archiveNamePrefix=

# 压缩包名字前缀.
archivePrefix=mainframe

# The location underwhich all of the build output will be collected.
collectingFolder=${archivePrefix}

# The list of {os, ws, arch} configurations to build.  This
# value is a ‘&’ separated list of ‘,’ separate triples.  For example,
#     configs=win32,win32,x86 & linux,motif,x86
# By default the value is *,*,*
#configs = *, *, *
configs=win32, win32, x86
# & \
#    win32,win32,x86_64 & \
#    win32,win32,wpf & \
#    linux, gtk, ppc & \
#    linux, gtk, x86 & \
#    linux, gtk, x86_64 & \
#    linux, motif, x86 & \
#    solaris, motif, sparc & \
#    solaris, gtk, sparc & \
#    aix, motif, ppc & \
#    hpux, motif, ia64_32 & \
#    macosx, carbon, ppc & \
#    macosx, carbon, x86 & \
#    macosx, cocoa, ppc & \
#    macosx, cocoa, x86 & \
#    macosx, cocoa, x86_64

# By default PDE creates one archive (result) per entry listed in the configs property.
# Setting this value to true will cause PDE to only create one output containing all
# artifacts for all the platforms listed in the configs property.
# To control the output format for the group, add a "group, group, group – <format>" entry to the
# archivesFormat.
#groupConfigurations=true

#The format of the archive. By default a zip is created using antZip.
#The list can only contain the configuration for which the desired format is different than zip.
#archivesFormat=win32, win32, x86 – antZip& \
#    linux, gtk, ppc – antZip &\
#    linux, gtk, x86 – antZip& \
#    linux, gtk, x86_64 – antZip& \
# linux, motif, x86 – antZip& \
#    solaris, motif, sparc – antZip& \
#    solaris, gtk, sparc – antZip& \
#    aix, motif, ppc – antZip& \
#    hpux, motif, PA_RISC – antZip& \
#    macosx, carbon, ppc – antZip

#Allow cycles involving at most one bundle that needs to be compiled with the rest being binary bundles.
allowBinaryCycles = true

#Sort bundles depenedencies across all features instead of just within a given feature.
flattenDependencies = true

#Parallel compilation, requires flattenedDependencies=true
#parallelCompilation=true
#parallelThreadCount=
#parallelThreadsPerProcessor=

#Set to true if you want the output to be ready for an update jar (no site.xml generated)
#outputUpdateJars = false

#Set to true for Jnlp generation
#codebase should be a URL that will be used as the root of all relative URLs in the output.
#generateJnlp=false
#jnlp.codebase=<codebase url>
#jnlp.j2se=<j2se version>
#jnlp.locale=<a locale>
#jnlp.generateOfflineAllowed=true or false generate <offlineAllowed/> attribute in the generated features
#jnlp.configs=${configs}            #uncomment to filter the content of the generated jnlp files based on the configuration being built

#Set to true if you want to sign jars
#signJars=false
#sign.alias=<alias>
#sign.keystore=<keystore location>
#sign.storepass=<keystore password>
#sign.keypass=<key password>

#Arguments to send to the zip executable
zipargs=

#Arguments to send to the tar executable
tarargs=

#Control the creation of a file containing the version included in each configuration – on by default
#generateVersionsLists=false

############## BUILD NAMING CONTROL ################
# Build目录,外部传入
buildDirectory=

# Build类型,一般是I, N, M, S, 什么的
buildType=I

# 输出的名字.
buildId=mainframe

# 输出目录名,结果里面会有个类似Imainframe这个目录
buildLabel=${buildType}.${buildId}

# 时间戳
timestamp=007

#The value to be used for the qualifier of a plugin or feature when you want to override the value computed by pde.
#The value will only be applied to plugin or features indicating build.properties, qualifier = context
#forceContextQualifier=<the value for the qualifier>

#Enable / disable the generation of a suffix for the features that use .qualifier.
#The generated suffix is computed according to the content of the feature
#generateFeatureVersionSuffix=true

############# BASE CONTROL #############
# Settings for the base Eclipse components and Java class libraries
# against which you are building.
# Base location for anything the build needs to compile against.  For example,
# in most RCP app or a plug-in,  the baseLocation should be the location of a previously
# installed Eclipse against which the application or plug-in code will be compiled and the RCP delta pack.

###就是eclipse-RCP-3.3.2-delta-pack和eclipse-RCP-3.3.2-win32的解压位置
baseLocation=${base}/target/eclipse

#Folder containing repositories whose content is needed to compile against
#repoBaseLocation=${base}/repos
#Folder where the content of the repositories from ${repoBaseLocation} will be made available as a form suitable to be compiled against
#transformedRepoLocation=${base}/transformedRepos

#Os/Ws/Arch/nl of the eclipse specified by baseLocation
baseos=win32
basews=win32
basearch=x86

#this property indicates whether you want the set of plug-ins and features to be considered during the build to be limited to the ones reachable from the features / plugins being built
filteredDependencyCheck=false

#this property indicates whether the resolution should be done in development mode (i.e. ignore multiple bundles with singletons)
resolution.devMode=false

#pluginPath is a list of locations in which to find plugins and features.  This list is separated by the platform file separator (; or :)
#a location is one of:
#- the location of the jar or folder that is the plugin or feature : /path/to/foo.jar or /path/to/foo
#- a directory that contains a /plugins or /features subdirectory
#- the location of a feature.xml, or for 2.1 style plugins, the plugin.xml or fragment.xml
#pluginPath=

skipBase=true
eclipseURL=<url for eclipse download site>
eclipseBuildId=<Id of Eclipse build to get>
eclipseBaseURL=${eclipseURL}/eclipse-platform-${eclipseBuildId}-win32.zip

############# MAP FILE CONTROL ################
# This section defines CVS tags to use when fetching the map files from the repository.
# If you want to fetch the map file from repository / location, change the getMapFiles target in the customTargets.xml

skipMaps=true
mapsRepo=:pserver:anonymous@example.com/path/to/repo
mapsRoot=path/to/maps
mapsCheckoutTag=HEAD

#tagMaps=true
mapsTagTag=v${buildId}

############ REPOSITORY CONTROL ###############
# 从CVS、SVN之类的地方获取代码.
# 例子:fetchTag=CVS=HEAD, SVN=v20050101
# fetchTag=HEAD
skipFetch=true

############# JAVA COMPILER OPTIONS ##############
# JDK/JRE的rt.jar的路径
#bootclasspath=${java.home}/lib/rt.jar

# 各种JRE 的路径. 通过Bundle-RequiredExecutionEnvironment指定的时候,就用下边这些了. 
# 用哪个,就把哪行去掉注释,改改。
#CDC-1.0/Foundation-1.0= /path/to/rt.jar
#CDC-1.1/Foundation-1.1=
#OSGi/Minimum-1.0=
#OSGi/Minimum-1.1=
#JRE-1.1=
#J2SE-1.2=
#J2SE-1.3=
#J2SE-1.4=
#J2SE-1.5=
#JavaSE-1.6=
#PersonalJava-1.1=
#PersonalJava-1.2=
#CDC-1.0/PersonalBasis-1.0=
#CDC-1.0/PersonalJava-1.0=
#CDC-1.1/PersonalBasis-1.1=
#CDC-1.1/PersonalJava-1.1=

# 编译LOG的后缀名
logExtension=.log

# 在生成的jar里是否包含调试信息
javacDebugInfo=false

# 有编译错误的时候是否失败
javacFailOnError=true

# 是否开启编译器的详细模式,会输出啰嗦的LOG
javacVerbose=true

# 传给java编译器的参数
compilerArg=-encoding UTF-8 -nowarn

# 源代码的默认版本. 没有设置Bundle-RequiredExecutionEnvironment的时候,用这个值
javacSource=1.6

# 生成目标版本. 没有设置Bundle-RequiredExecutionEnvironment的时候,用这个值
javacTarget=1.6



以下是一些经验总结:
=======================================
运行,报一个jar包找不到,把缺少的org.eclipse.core.runtime.compatibility.registry_3.3.0.v20100520.jar
放到D:\RCP_pack\buildEnv\RCP-build-require\target\eclipse\plugins目录下。
只要是jar包找不到,就往这个目录放。
===============================
路径相关的变量,路径里面用/,而不是\。
========================================================
遭遇让人郁闷的错误,Missing required plug-in
     [java] BUILD FAILED
     [java] D:\RCP_pack\buildEnv\eclipse\plugins\org.eclipse.pde.build_3.6.1.R3
x_v20100823\scripts\productBuild\productBuild.xml:39: The following error occur
ed while executing this line:
     [java] D:\RCP_pack\buildEnv\eclipse\plugins\org.eclipse.pde.build_3.6.1.R3
x_v20100823\scripts\productBuild\productBuild.xml:69: Bundle mainframe_1.0.0.20
102231142 failed to resolve.:
     [java]     Missing required plug-in org.eclipse.ui.ide_0.0.0.
     [java]     Missing required plug-in org.eclipse.core.resources_3.6.0.
     [java]     Missing required plug-in org.eclipse.ui.console_3.5.0.

往RCP-build-require\target\eclipse\plugins下复制了一个ui.ide的jar包,没反应。
到处放,怎么都不行,十分郁闷。
后来,干脆,把大Eclipse目录下plugins下的所有org.eclipse开头的jar包都复制过来了,竟然就没问题了。
或许这样不好,但毕竟能往下跑了。

基本上,只要说没找到哪个类的,就是缺jar包了。
复制那一个jar包,可能还不好使。
-------------------------
某老外Patrick说,可以让
baseLocation=${eclipseLocation}
也就是不用RCP-build-require/target下的eclipse目录,而用大Eclipse目录,
会简单一些,但是不好,这样就和大eclipse环境依赖起来了。
试了下,确实可以,不过,我上步已经搞定了(不过,也复制了N多Jar包),所以不需要这么做了。
======================================================
     [java] [eclipse.buildScript] Bundle org.eclipse.jdt.launching:
     [java] [eclipse.buildScript]       Missing required plug-in org.eclipse.jdt
.debug_[3.5.0,4.0.0).
这种不用理它,貌似大家都有这东西,无影响。
======================================================
然后,是下一个问题。
java源代码是UTF-8格式的,自动生成的build.xml里javac部分没有指定encoding,build过程会报错。

下面是D:\RCP_pack\buildResult\mainframe\plugins\mainframe\build.xml的一部分。
<!-- compile the source code -->
<javac destdir="${build.result.folder}/@dot" failonerror="${javacFailOnError}" verbose="${javacVerbose}" debug="${javacDebugInfo}" includeAntRuntime="no" bootclasspath="${bundleBootClasspath}" source="${bundleJavacSource}" target="${bundleJavacTarget}" errorProperty="compilation.error.occured"        >
    <compilerarg line="${compilerArg}" compiler="${build.compiler}"/>
    <classpath refid="@dot.classpath" />
    <src path="src/"            />
    <compilerarg value="@${basedir}/javaCompiler...args" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"            />
    <compilerarg line="-log '${build.result.folder}/@dot${logExtension}'" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"            />
</javac>

这个build.xml是build过程中自动生成的,类似于Eclipse中,在build.properties上右键/PDE Tools/Create Ant Build File,
生成的内容是类似的,只是路径什么的有不同。
(1)开始想这个build.xml会有个模板,可能在哪个jar包里放着,
我找到它,直接在javac加上encoding="UTF-8"就行了,搜了半天没找到。

(2)后来又想,ant应该有个默认的文件编码,能否修改它呢。搜了半天,
在批处理前面加了“set ANT_OPTS=-Dfile.encoding=UTF-8”,没效果。

(3)又想,堂堂的NB脚本不应该如此没有扩展性,看到
<compilerarg line="${compilerArg}" compiler="${build.compiler}"/>
感觉这个${compilerArg}应该是用来扩展用的参数,在build.xml中搜之,
发现只是开头声明了一个空值,<property name="compilerArg" value=""/>
感觉,它应该是特意留的,外部可以给这个变量赋值。
修改我的build.xml的<target name="pde-build">部分,
追加参数<arg value="-DcompilerArg=-encoding UTF-8" />,好使了,开心!!!
======================================================
build结果在D:\RCP_pack\buildResult\mainframe\I.mainframe\mainframe-win32.win32.x86.zip
就是这个zip包,复制走就可以了。

bin.includes指定的那些文件不是原样复制到结果里的,是打在plugin/main...你自己的jar包里的,
运行一次程序后,就放到
D:\RCP_pack\buildResult\mainframe\I.mainframe\mainframe\configuration\org.eclipse.osgi目录下了。

如果生成的结果运行出错,那就是缺少jar包或其它资源文件了,
jar包在plugin.xml和product的依赖里加,资源文件在bin.includes里加。
=======================================================


Any code you wish to reference in your RCP application needs to be in a plug-in project, not a basic Java project. There is no way for plug-in code to reference Java project code at runtime, even though it will appear to compile.
-------------------------------
To reference your web service classes you will need to turn your Java project into a Plug-in Project (which basically means you’ll be adding a manifest.mf file). It is common to have a JAR that is used both inside and outside of an RCP app. I usually advise people to just make the JAR into a plug-in so it can be used either way. A plug-in is really just a JAR with some extra manifest entries, so it doesn’t seem like a big deal.

------------------------------
Do you mean you want to build a feature instead of a complete product? If so, see my answer to Stefanko on March 10. One thing I forgot to point out was that you need to change the PDE build script from productBuild.xml to build.xml. You can find the build.xml file one directory up from the productBuild.xml file.

And here’s a newsgroup post showing how to fill in the allElements.xml file:

http://dev.eclipse.org/mhonarc/lists/pde-build-dev/msg00673.html


----------------------------
Try commenting out the “javacVerbose” property in your build.properties file.
I added “-nowarn” to compilerArg, und it works now.

I don’t how to check “icon” folder in build.properties, but I include the image file in menifest, it works now. thanks a lot for your reply.

-----------------------------
I want now build a rcp plug-in, but not the product. how can I modify these sripts, so that I only build the plug-ins or features.

1. Comment out the product entry in the build.properties file.
2. Change the PDE build script from productBuild.xml to build.xml. You can find the build.xml file one directory up from the productBuild.xml file.
3. Copy allElements.xml from the org.eclipse.pde.build plug-in and replace the ids in the file with the id of your feature.

Here is an example of a filled out allElements.xml file.

http://dev.eclipse.org/mhonarc/lists/pde-build-dev/msg00673.html
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved