`
lurma
  • 浏览: 8115 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

利用Ant脚本导出BIRT

    博客分类:
  • BIRT
阅读更多

       最近公司在对birt进行二次开发,需要对birt进行自动化编译,因此对其研究了一番,写了下面的这篇文章,希望对初学者有些帮助。

谈到自动化编译,很容易让人想到ant工具,到网上找些资料,还是有些不错的,像下面的:

         meteors1113的专栏的使用Ant导出Eclipse RCP全攻略  

         网址:http://blog.csdn.net/meteors1113/article/details/5522538

       这篇文章对于单插件和多插件导出RCP产品都是可以导出的,但是对于BIRT来讲,还是差了些东西,因为BIRT的插件工程有二百多个,各插件之间的依赖关系比较复杂,本文也是在这篇博文的基础上做些修改和调整,原理其实是一样的,都是利用PDE进行编译和打包。

       下面就来说说利用ant脚本打包编译BIRT的步骤:

 

1. 下载birt源码

       这里就不作介绍了,网上还是有很多资料的,本文用的是birt3.7.0的源码;

       还有一点要说明,自己手动下载源码跟通过cvs下载的源码结构不太一样,cvs下载的源码结构不太一样,手动下载的包含编译时所依赖的jar包,但是cvs下载的源码得自己来配置所需要的jar包,建议大家选择手动下载,如果用cvs下载的也没关系,本文就是用cvs下载的源码,不包含依赖包。

 

2. 搭建环境

       在源码下载完成后,需要修改源码目录的结构,并且放到设定好的目录中,整个环境的结构如下所示(假设是在D盘);

            

           D:\BIRT-BUILD

                    |------build

                             |-------features

                             |-------plugins

                    |------repos

                             |-------rcp

                    |------target

 

       创建完目录后,将源码复制到plugins目录中,然后将源码中的feature类型的工程剪贴到features文件夹中,以nl1结尾的国际化工程和所有的测试工程都要放到plugins文件夹中,不能放到子目录中,否则会出现插件找不到的问题。

       源码配置好以后,就需要下载各种的环境包,列表如下:

                eclipse-SDK-3.7.2-win32.zip(网址待更新)

                eclipse-3.7.2-delta-pack.zip(网址待更新)

                org.eclipse.rcp-3.7.2.zip(网址待更新)

                emf2.6.x( http://archive.eclipse.org/modeling/emf/emf/downloads/drops/)

                GEF-ALL-3.7.2(网址待更新)

                dtp-sdk_1.9.x(网址待更新)

 

       下载完成后,将eclipse-SDK-3.7.2-win32.zip解压到target中,解压后的目录:

     

                target

                    |----eclipse

 

       这个target文件夹就是用来放置eclipse的,之后的PDE就是从这里调用。

       解压eclipse-3.7.2-delta-pack.zip到eclipse目录,并进行替换。如果不解压eclipse-3.7.2-delta-pack的话,发布的RCP程序将没有可执行程序(eclipse.exe)。

       解压org.eclipse.rcp-3.7.2.zip到rcp目录下,emf、gef以及dtp包都解压到eclipse目录中。

       如果你已经手动下载了3.7.0源码的话,就将源码plugins文件夹下的所有jar包以及下列文件夹复制到eclipse目录下的plugins文件夹中:

               javax.xml.rpc_1.1.0.v201005080400

                javax.xml.soap_1.2.0.v201005080501

               org.apache.axis_1.4.0.v201005080400

               org.apache.commons.discovery_0.2.0.v201004190315

               org.w3c.sac

      

       如果没有手动下载3.7.0源码的话(如果下载了那就更容易了,环境都省了好多,话又说回来,如果手动下载了源码的话,那谁还这么麻烦的用cvs下载的源码来搭建环境啊),建议下载EclipseIDE for Java and Report Developers 简称eclipse4report,地址: http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-reporting-juno-SR1-win32.zip ,这个IDE包含birt的功能,因此在plugins里会有编译所依赖的一些插件,缺少插件时可以到这个IDE中去copy,不然的话,找这些个插件会挺麻烦的。

 

3. 编写脚本

       在eclipse中创建一个一般工程,名为org.eclipse.birt.report.designer.build,里面创建两个文件,build.properties和build.xml,这两个文件是最关键的文件,最终编译就靠这两个文件,也就是ant脚本。 

        build.xml文件内容如下:

<project name="org.eclipse.birt.report.designer.build" default="build">
    <property file="build.properties" />
    <!--
        Paths that allow running PDE Build without knowing specific bundle versions    
    -->
    <path id="equinox.launcher.path">
        <fileset dir="${eclipseLocation}/plugins">
            <include name="org.eclipse.equinox.launcher_*.jar" />
        </fileset>
    </path>
    <property name="equinox.launcher" refid="equinox.launcher.path" />
    <path id="pde.build.dir.path">
        <dirset dir="${eclipseLocation}/plugins">
            <include name="org.eclipse.pde.build_*" />
        </dirset>
    </path>
    <property name="pde.build.dir" refid="pde.build.dir.path" />
            
    <!--
        This target actually executes the PDE Build process by launching the
        Eclipse antRunner application.
    -->
    <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="${pde.build.dir}/scripts/productBuild/productBuild.xml" />
            <arg value="-Dtimestamp=${timestamp}" />
            <classpath>
                <pathelement location="${equinox.launcher}" />
            </classpath>
        </java>
    </target>
    <target name="clean">
        <delete dir="${buildDirectory}" />
    </target>
    <target name="build" depends="pde-build" />
</project>

 

build.properties文件内容如下:

       

###############################################################################
# Copyright (c) 2003, 2009 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
###############################################################################
#####################
             
eclipseLocation=D:/BIRT-BUILD/target/eclipse
pde.build.includeFetch=true
generateSourceReferences=true
product=D:/BIRT-BUILD/build/plugins/org.eclipse.birt.report.designer.ui.rcp/BIRT.product
             
runPackager=true
basedir=D:/BIRT-BUILD
             
# The prefix that will be used in the generated archive.
archivePrefix=BIRT
             
# The directory into which the build elements are fetched and where
# the build takes place.
buildDirectory=D:/BIRT-BUILD/build
             
# 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
             
#Allow cycles involving at most one bundle that needs to be compiled with the rest being binary bundles.
allowBinaryCycles = true
             
#Arguments to send to the zip executable
zipargs=
             
#Arguments to send to the tar executable
tarargs=
             
# Type of build.  Used in naming the build output.  Typically this value is
# one of I, N, M, S, ...
buildType=I
             
# ID of the build.  Used in naming the build output.
buildId=BIRT
             
# Label for the build.  Used in naming the build output
buildLabel=${buildType}.${buildId}
             
# Timestamp for the build.  Used in naming the build output
timestamp=007
             
base=D:/BIRT-BUILD
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=${buildDirectory}/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=${buildDirectory}/transformedRepos/features/
             
skipBase=true
eclipseURL=<url for eclipse download site>
eclipseBuildId=<Id of Eclipse build to get>
eclipseBaseURL=${eclipseURL}/eclipse-platform-${eclipseBuildId}-win32.zip
             
skipMaps=true
mapsRepo=:pserver:anonymous@example.com/path/to/repo
mapsRoot=path/to/maps
mapsCheckoutTag=HEAD
             
             
#tagMaps=true
mapsTagTag=v${buildId}
             
skipFetch=true
             
# Specify the output format of the compiler log when eclipse jdt is used
logExtension=.log
             
# Whether or not to include debug info in the output jars
javacDebugInfo=false

  

4. 编写批处理文件

       windows的bat为例。在windows中进入org.eclipse.birt.report.designer.build的目录,创建一个bat文件(比如build.bat ),内容如下: 

rem 设置java jdk的路径,本文用的是jdk1.5.0_22
set JAVA_HOME=D:/DevTools/jdk1.6.0_19
rem 设置ant路径,本文用的是ant-1.8.2
set ANT_HOME=D:/DevTools/apache-ant-1.7.1
%ANT_HOME%/bin/ant.bat -file build.xml
 

        以后每次打包就可以只运行这个bat文件了。

       设置java jdk的路径,本文用的是jdk1.5.0_22设置ant路径,本文用的是ant-1.8.2

 

5. 常见问题

       双击运行批处理的时候,很有可能会出现问题,但是窗口会闪退,因此最好在命令提示符中运行批处理文件。

       下面对运行脚本的过程中可能会出现的一些问题进行一下说明:

    

       运行脚本,会出现如下问题:

[java]BUILD FAILED
[java]D:\BIRT-BUILD\target\eclipse\plugins\org.eclipse.pde.build_3.7.0.v20111116-2009\scripts\productBuild\productBuild.xml:39:The following error occurred while executing this line:
[java]D:\BIRT-BUILD\target\eclipse\plugins\org.eclipse.pde.build_3.7.0.v20111116-2009\scripts\productBuild\productBuild.xml:69:Unable to find plug-in: com.lowagie.text_0.0.0. Please check the error log formore details.
[java]
[java]Total time: 4 seconds
[java]An error has occurred. See the log file

 

       由异常信息可以知道,导致编译失败的原因是由于缺少com.lowagie.text插件,到eclipse4report目录下plugins文件夹中复制过来即可。

 

       再次运行,会出现以下错误:

[java]BUILD FAILED
[java]D:\BIRT-BUILD\target\eclipse\plugins\org.eclipse.pde.build_3.7.0.v20111116-2009\scripts\productBuild\productBuild.xml:39:The following error occurred while executing this line:
[java]D:\BIRT-BUILD\target\eclipse\plugins\org.eclipse.pde.build_3.7.0.v20111116-2009\scripts\productBuild\productBuild.xml:69:Bundle com.shentong.kfront.designer.gdm_1.0.0.201302261654 failed to resolve.:
[java]     Missing required plug-inorg.eclipse.birt.report.model_3.7.0.
[java]     Missing required plug-inorg.eclipse.birt.report.designer.core_3.7.0.
[java]     Missing required plug-inorg.eclipse.birt.report.designer.ui_3.7.0.
[java]     Missing required plug-inorg.eclipse.birt.report.designer.ui.views_3.7.0.
[java]     Missing required plug-inorg.eclipse.birt.core_3.7.0.
[java]     Missing required plug-inorg.eclipse.birt.report.designer.ui.data_3.7.0.
[java]     Missing required plug-in org.eclipse.birt.report.data.adapter_3.7.0.
[java]     Missing required plug-inorg.eclipse.birt.data_3.7.0.
[java]     Unsatisfied import packageorg.eclipse.birt.report.engine.api_0.0.0.
[java]     Unsatisfied import packageorg.eclipse.birt.report.engine.api.impl_0.0.0.
[java]     Unsatisfied import packageorg.eclipse.birt.report.model.adapter.oda.impl_0.0.0.
[java]
[java]
[java]Total time: 5 seconds
[java]An error has occurred. See the log file
 

       在eclipse4report目录下plugins文件夹中找到如下插件并导入:

              org.apache.batik.*.jar  (以org.apache.batik开头的都要导入)

              org.mozilla.javascript_*.jar

              org.w3c.css.sac_*.jar

              org.w3c.dom.events_*.jar

              org.w3c.dom.smil_*.jar

              org.w3c.dom.svg_*.jar

       

       导入后运行脚本:

[java]BUILD FAILED
[java]D:\BIRT-BUILD\target\eclipse\plugins\org.eclipse.pde.build_3.7.0.v20111116-2009\scripts\productBuild\productBuild.xml:39:The following error occurred while executing this line:
[java]D:\BIRT-BUILD\target\eclipse\plugins\org.eclipse.pde.build_3.7.0.v20111116-2009\scripts\productBuild\productBuild.xml:69:Unable to find plug-in: javax.xml.rpc_0.0.0. Please check the error log formore details.
[java]
[java]Total time: 4 seconds
[java]An error has occurred. See the log file
 

       还是报找不到插件的异常,同理,缺少哪个插件,到eclipse4report中复制过来即可。

       导入完成后,脚本应该就可以正常编译了,但是打包出来的产品可能会出现如下的问题:

java.lang.RuntimeException:Application "{0}" could not be found in the registry. Theapplications available are: org.eclipse.equinox.app.error, org.eclipse.help.base.infocenterApplication,org.eclipse.help.base.helpApplication, org.eclipse.help.base.indexTool,org.eclipse.update.core.standaloneUpdate,org.eclipse.update.core.siteOptimizer.
       atorg.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:248)
       at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:29)
       at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
       atorg.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
       atorg.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
       atorg.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
       atsun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       atjava.lang.reflect.Method.invoke(Method.java:597)
       at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
       atorg.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
       atorg.eclipse.equinox.launcher.Main.run(Main.java:1410)
 

       造成这个问题的原因有很多种,我只说我遇到的,在将下载的包导入到eclipse中时,很有可能会出现版本冲突的问题,在运行脚本的时候就是因为如下包的版本不对,才出现了如上所示的异常:

              org.w3c.dom.smil_*.jar

版本本该是1.0.0.*,但是由于导入了1.0.1版本的jar包,导致出现了上述的问题。

 

       继续运行批处理文件,解决了以上的问题后,应该会成功的导出BIRT产品的,祝大家成功!!!

 

1
1
分享到:
评论

相关推荐

    利用ant脚本 自动构建svn增量.docx

    **利用Ant脚本进行SVN增量构建** 1. **基本流程** - **获取代码**:首先,Ant脚本会从SVN仓库中检出或更新最新的代码到本地工作目录。 - **增量分析**:通过比较上一次构建与当前版本的差异,找出新增或修改的文件...

    teamcity-ant脚本.rar

    在TeamCity中,Ant脚本扮演着至关重要的角色,因为Ant是Java项目常用的构建工具,能够定义和执行构建过程。下面我们将深入探讨TeamCity与Ant脚本的结合使用及其相关知识点。 1. **Ant简介** Ant是Apache软件基金会...

    ant脚本运行junit测试用例

    通过ant对各种语言脚本做运行管理,并输出报告!

    ant脚本资料ant

    - **XML结构**:Ant脚本以XML格式编写,遵循特定的命名空间和元素结构,如`&lt;project&gt;`、`&lt;target&gt;`、`&lt;task&gt;`等。 - **属性(Attribute)**:任务通常有属性,用来设置参数,例如`srcdir`用于指定源代码目录,`...

    ant 脚本从svn上取代码打包代码全,同时包括相关的jar包

    在给定的场景中,"ant 脚本从svn上取代码打包代码全,同时包括相关的jar包",这意味着我们需要了解如何用Ant配合Subversion(SVN)进行代码管理,并打包项目,同时处理依赖的jar文件。 首先,让我们来看看Ant脚本的...

    ant脚本-build.xml

    ant脚本例子,一个build.xml模板, 修改后直接运行。

    ant脚本通用模板 ant脚本通用模板

    ### ant脚本通用模板知识点详解 #### 一、Ant简介 Apache Ant 是一个Java环境下的构建工具,主要用于编译、测试、部署等任务的自动化执行。Ant使用XML格式来描述构建过程,使得整个构建流程清晰易懂。对于中小型...

    通过ant脚本,编译打包android工程

    通过ant脚本,编译打包android工程。 编译打包android工程的ant脚本,Android官方提供的打包脚本。 有注释

    常用的ANT蚂蚁脚本

    总结来说,"常用的ANT蚂蚁脚本"涵盖了使用ANT配合XDoclet自动创建Hibernate映射文件,以及利用ANT自动化EJB项目的构建和部署流程。这些脚本对于理解ANT的工作原理,以及在实际开发环境中如何使用ANT进行项目管理具有...

    Ant脚本详解说明

    Ant是一个Apache基金会下的跨平台的构件工具,它可以实现项目的自动构建和部署等功能。在本文中,主要熟悉怎样将Ant应用到Java项目中,让它简化构建和部署操作。

    shell脚本+ant脚本

    Shell脚本和Ant脚本是两种在IT行业中广泛使用的自动化工具,主要应用于Unix/Linux系统和Java项目的构建。这里我们将深入探讨这两个概念以及它们在实际工作中的应用。 首先,Shell脚本是基于Unix/Linux命令行环境的...

    ant脚本编译jar

    本文将深入探讨如何使用`Ant`脚本来编译并创建一个`JAR`文件,以此来理解`Ant`脚本的工作原理和实际应用。 `Ant`是Apache软件基金会开发的一款开源构建工具,它使用XML格式定义构建过程,具有高度可配置性和可扩展...

    Ant构建中使用JS脚本方法

    在Ant构建过程中,JavaScript脚本方法的使用是一个强大的工具,它允许开发者自定义构建过程,实现更复杂的逻辑和任务自动化。Ant是一个Java库和命令行工具,它的设计目标是驱动软件构建过程,尤其是在Java项目中。这...

    java项目ant打包脚本

    Java项目中的Ant打包脚本是开发过程中的一个重要环节,它使得开发者能够自动化构建、测试和部署应用程序。Ant是一个基于XML的构建工具,由Apache软件基金会开发,它在Java社区广泛使用,替代了早期的Makefile,因为...

    Ant和批处理脚本.rar

    这样的组合既利用了Ant的灵活性和跨平台能力,又发挥了批处理脚本在Windows环境下的便利性。 在"Ant和批处理脚本.rar"这个压缩包中,可能包含了Ant的构建文件示例、批处理脚本模板,以及相关的说明文档。用户可以...

    我的ant脚本

    我的ant脚本,用于打包文件,其中包含了常见的jar包工具,学习常用的ant命令

    Ant 脚本详解

    在本文中,我们将深入探讨Ant脚本的各个方面。 ### Ant的基本结构 Ant的核心是构建文件,这个文件通常以XML格式编写,包含了多个目标(target)和任务(task)。目标是一系列任务的集合,它们按照特定顺序执行。...

    ant脚本,打可运行的jar包,并导出第三方jar包到指定目录

    描述中提到的"并导出第三方jar包到指定目录"意味着在构建过程中,Ant会识别项目依赖的外部库,并将它们复制到一个特定的目录。这样做的好处是,可以清晰地分离项目自身的代码和外部依赖,便于管理和更新依赖库,同时...

    分享一个项目的Ant脚本配制

    标题中的“分享一个项目的Ant脚本配置”表明我们将探讨的是如何使用Apache Ant工具来构建和管理Java项目。Ant是开源的构建工具,广泛应用于Java项目,它可以自动化编译、打包、测试等开发流程。 在描述中提到的...

    eclipse下利用ant、junit进行自动化测试例子源码

    本示例主要展示了如何在Eclipse集成开发环境中利用ANT构建工具和JUnit单元测试框架进行自动化测试。以下是关于这些知识点的详细说明: 1. **Eclipse IDE**:Eclipse是一款流行的开源Java开发环境,支持多种语言的...

Global site tag (gtag.js) - Google Analytics