当前位置: 代码迷 >> Web前端 >> web project中手动嵌入birt运作支持 2.5.2, 3.7.2
  详细解决方案

web project中手动嵌入birt运作支持 2.5.2, 3.7.2

热度:208   发布时间:2012-07-26 12:01:08.0
web project中手动嵌入birt运行支持 2.5.2, 3.7.2

嵌入birt 2.5.2

准备

下载birt-runtime-2_5_2.zip

地址http://download.eclipse.org/birt/downloads/build.php?build=R-R1-2_5_2-201002221500

?

步骤

1、? 新建web工程

2、? 解压birt-runtime-2_5_2.zip,将其中的WebViewerExample目录(解压birt.war也可以)下的logsreportscriptlibwebcontent目录拷贝到新建项目的web根目录(如WebContent),将WebViewerExample/WEB-INF下的libplatformtlds目录及jrun.web.xmlserver-config.wsddviewer.properties文件拷到新建项目的WEB-INF目录下。

3、? 打开WebViewerExample/WEB-INFweb.xml文件,拷贝里的配置到新建项目的web.xml里,内容如下:

	<!-- Default locale setting.
	-->
	<context-param>
		<param-name>BIRT_VIEWER_LOCALE</param-name>
		<param-value>en-US</param-value>
	</context-param>

	<!-- 
		Default timezone setting.
		Examples: "Europe/Paris", "GMT+1".
		Defaults to the container's timezone.		
	 -->
	<context-param>
		<param-name>BIRT_VIEWER_TIMEZONE</param-name>
		<param-value></param-value>
	</context-param>
	
	<!--
		Report resources directory for preview. Defaults to ${birt home}
	-->
	<context-param>
		<param-name>BIRT_VIEWER_WORKING_FOLDER</param-name>
		<param-value></param-value>
	</context-param>
	
	<!--
		Temporary document files directory. Defaults to ${birt home}/documents
	-->
	<context-param>
		<param-name>BIRT_VIEWER_DOCUMENT_FOLDER</param-name>
		<param-value></param-value>
	</context-param>

	<!--
		Flag whether the report resources can only be accessed under the
		working folder. Defaults to true
	-->
	<context-param>
		<param-name>WORKING_FOLDER_ACCESS_ONLY</param-name>
		<param-value>true</param-value>
	</context-param>

	<!--
		Temporary image/chart directory. Defaults to ${birt home}/report/images
	-->
	<context-param>
		<param-name>BIRT_VIEWER_IMAGE_DIR</param-name>
		<param-value></param-value>
	</context-param>

	<!-- Engine log directory. Defaults to ${birt home}/logs -->
	<context-param>
		<param-name>BIRT_VIEWER_LOG_DIR</param-name>
		<param-value></param-value>
	</context-param>

	<!-- Report engine log level -->
	<context-param>
		<param-name>BIRT_VIEWER_LOG_LEVEL</param-name>
		<param-value>WARNING</param-value>
	</context-param>

	<!--
		Directory where to store all the birt report script libraries (JARs).
		Defaults to ${birt home}/scriptlib
	-->
	<context-param>
		<param-name>BIRT_VIEWER_SCRIPTLIB_DIR</param-name>
		<param-value></param-value>
	</context-param>
	
	<!-- Resource location directory. Defaults to ${birt home} -->
	<context-param>
		<param-name>BIRT_RESOURCE_PATH</param-name>
		<param-value></param-value>
	</context-param>

	<!-- Preview report rows limit. An empty value means no limit. -->
	<context-param>
		<param-name>BIRT_VIEWER_MAX_ROWS</param-name>
		<param-value></param-value>
	</context-param>

	<!--
		Max cube fetch levels limit for report preview (Only used when
		previewing a report design file using the preview pattern)
	-->
	<context-param>
		<param-name>BIRT_VIEWER_MAX_CUBE_ROWLEVELS</param-name>
		<param-value></param-value>
	</context-param>
	<context-param>
		<param-name>BIRT_VIEWER_MAX_CUBE_COLUMNLEVELS</param-name>
		<param-value></param-value>
	</context-param>

	<!-- Memory size in MB for creating a cube. -->
	<context-param>
		<param-name>BIRT_VIEWER_CUBE_MEMORY_SIZE</param-name>
		<param-value></param-value>
	</context-param>

	<!-- Defines the BIRT viewer configuration file -->
	<context-param>
		<param-name>BIRT_VIEWER_CONFIG_FILE</param-name>
		<param-value>WEB-INF/viewer.properties</param-value>
	</context-param>

	<!--
		Flag whether to allow server-side printing. Possible values are "ON"
		and "OFF". Defaults to "ON".
	-->
	<context-param>
		<param-name>BIRT_VIEWER_PRINT_SERVERSIDE</param-name>
		<param-value>ON</param-value>
	</context-param>

	<!--
		Flag whether to force browser-optimized HTML output. Defaults to true
	-->
	<context-param>
		<param-name>HTML_ENABLE_AGENTSTYLE_ENGINE</param-name>
		<param-value>true</param-value>
	</context-param>

	<!--
		Filename generator class/factory to use for the exported reports.
	-->
	<context-param>
		<param-name>BIRT_FILENAME_GENERATOR_CLASS</param-name>
		<param-value>org.eclipse.birt.report.utility.filename.DefaultFilenameGenerator</param-value>
	</context-param>

	<!--
		Viewer Filter used to set the request character encoding to UTF-8.
	-->
	<filter>
    	<filter-name>ViewerFilter</filter-name>
        <filter-class>org.eclipse.birt.report.filter.ViewerFilter</filter-class>
	</filter>
    <filter-mapping>
        <filter-name>ViewerFilter</filter-name>
        <servlet-name>ViewerServlet</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>ViewerFilter</filter-name>
        <servlet-name>EngineServlet</servlet-name>
    </filter-mapping>
    				
	<!-- Viewer Servlet Context Listener -->
	<listener>
		<listener-class>org.eclipse.birt.report.listener.ViewerServletContextListener</listener-class>
	</listener>

	<!-- Viewer HttpSession Listener -->
	<listener>
		<listener-class>org.eclipse.birt.report.listener.ViewerHttpSessionListener</listener-class>
	</listener>
	
	<!-- Viewer Servlet, Supports SOAP -->
	<servlet>
		<servlet-name>ViewerServlet</servlet-name>
		<servlet-class>org.eclipse.birt.report.servlet.ViewerServlet</servlet-class>
	</servlet>

	<!-- Engine Servlet -->
	<servlet>
		<servlet-name>EngineServlet</servlet-name>
		<servlet-class>org.eclipse.birt.report.servlet.BirtEngineServlet</servlet-class>
	</servlet>

	<servlet-mapping>
		<servlet-name>ViewerServlet</servlet-name>
		<url-pattern>/frameset</url-pattern>
	</servlet-mapping>
	
	<servlet-mapping>
		<servlet-name>ViewerServlet</servlet-name>
		<url-pattern>/run</url-pattern>
	</servlet-mapping>
	
	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/preview</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/download</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/parameter</url-pattern>
	</servlet-mapping>	

	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/document</url-pattern>
	</servlet-mapping>	

	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/output</url-pattern>
	</servlet-mapping>	
	
	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/extract</url-pattern>
	</servlet-mapping>

	<jsp-config>
		<taglib>
			<taglib-uri>/birt.tld</taglib-uri>
			<taglib-location>/WEB-INF/tlds/birt.tld</taglib-location>
		</taglib>
	</jsp-config>

?

?

4、? 如果开发需要连接数据库,则需要将数据库驱动包拷贝到新建项目的WEB-INF/platform/plugins/org.eclipse.birt.report.data.oda.jdbc_2.5.2.v20100205/drivers里;如果使用的是tomcat6.0,还需要下载commons-logging-api.jar并导入到新建项目(加到WEB-INF/lib中)。

5、? web根目录(WebContent)下新建文件夹reports,之后的报表文件(*.rptdesign)就统一放到这里进行管理了。这一步不必要,在234步时已经完成嵌入birt的工作了。

6、? 这一步也不必要,有需要的话再看吧,否则请忽视。修改web配置里面的BIRT_VIEWER_LOG_DIR BIRT_VIEWER_IMAGE_DIR BIRT_VIEWER_SCRIPTLIB_DIR的配置,指定到你想要的目录,可以指定的WEB-INF目录里,默认的路径是

log -- <web根目录>/ logs

image -- <web根目录>/report/images

scriptlib -- <web根目录>/ scriptlib

documents -- <web根目录>/ documents

?

以下是我的目录结构:

?

?

?

注:以上步骤只是在web项目里嵌入birt的运行支持,至于开发.rptdesign的插件就要读者自己找了,可以下载一个rcp(文件是birt-rcp-report-designer-2_5_2.zip)来编辑.rptdesign文件,rcp也在这个地址http://download.eclipse.org/birt/downloads/build.php?build=R-R1-2_5_2-201002221500下载。birt-rcp-report-designer-2_5_2.zip是一个eclipse,但是里面只有.rptdesign文件的开发插件,没有其他,想当的轻量级的eclipse。把开发好的.rptdesign放到上面新建项目的web根目录里就行了,或者放到其下的reports目录里,但是访问路径要记得写正确了,你懂的,不多说了。

?

嵌入birt 3.7.2

准备

下载birt-runtime-3_7_2.zip

地址http://download.eclipse.org/birt/downloads/build.php?build=R-R1-3_7_2-201202141408

步骤

嵌入版本3.7.22.5.2的方法差不多,最大的区别就是3.7.2的没有了platform目录,在tomcat6.0的运行环境也无需导入commons-logging-api.jar包。

可参考嵌入birt 2.5.2的步骤,在第2步中拷贝的文件一样,只是没有platform目录,在第4步中无需拷贝commons-logging-api.jar包,只需要将数据库驱动包加到WEB-INF/lib就行了。

?

以下是我的目录结构:

  相关解决方案