Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
BIRT错误:无法确定Java中的默认工作区位置_Java_Birt - Fatal编程技术网

BIRT错误:无法确定Java中的默认工作区位置

BIRT错误:无法确定Java中的默认工作区位置,java,birt,Java,Birt,我得到以下错误 java.lang.IllegalStateException: Unable to determine the default workspace location. Check your OSGi-less platform configuration of the plugin or datatools workspace path. 这没什么意义 报告是在Eclipse中使用BIRT设计器创建的,我们使用代码将报告转换为PDF格式 代码看起来像 final E

我得到以下错误

java.lang.IllegalStateException: Unable to determine the default workspace location.  Check your OSGi-less platform configuration of the plugin or datatools workspace path.
这没什么意义

报告是在Eclipse中使用BIRT设计器创建的,我们使用代码将报告转换为PDF格式

代码看起来像

    final EngineConfig config = new EngineConfig();
    config.setBIRTHome("./birt");
    Platform.startup(config);
    final IReportEngineFactory factory = (IReportEngineFactory) Platform
            .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);

    final HTMLRenderOption ho = new HTMLRenderOption();
    ho.setImageHandler(new HTMLCompleteImageHandler());
    config.setEmitterConfiguration(RenderOption.OUTPUT_FORMAT_HTML, ho);
    // Create the engine.
    this.engine = factory.createReportEngine(config);
    final IReportRunnable report = this.engine.openReportDesign(reportName);
    final IRunAndRenderTask task = this.engine.createRunAndRenderTask(report);
    final RenderOption options = new HMTLRenderOption();
    options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);
    options.setOutputFormat("pdf");
    final String output = reportName.replaceFirst(".rptdesign", ".xls");
    final String output = name.replaceFirst(".rptdesign", "." + HTMLRenderOption.OUTPUT_FORMAT_PDF);
    options.setOutputFileName( outputReporttName);
    task.setRenderOption(options);


    // Run the report.
    task.run();
但是在task.run()方法中,系统似乎抛出了错误

这需要能够独立运行,而不需要eclipse,并且希望BIRT home的设置会让它变得很好,但这些似乎是我不知道的,可能不需要的其他连接配置文件

完整错误:

07-Jan-2013 14:55:31 org.eclipse.datatools.connectivity.internal.ConnectivityPlugin log
SEVERE: Unable to determine the default workspace location.  Check your OSGi-less      platform configuration of the plugin or datatools workspace path.
07-Jan-2013 14:55:31 org.eclipse.birt.report.engine.api.impl.EngineTask handleFatalExceptions
SEVERE: An error happened while running the report. Cause:
java.lang.IllegalStateException: Unable to determine the default workspace location.  Check your OSGi-less platform configuration of the plugin or datatools workspace path.
at org.eclipse.datatools.connectivity.internal.ConnectivityPlugin.getDefaultStateLocation(ConnectivityPlugin.java:155)
at org.eclipse.datatools.connectivity.internal.ConnectivityPlugin.getStorageLocation(ConnectivityPlugin.java:191)
at org.eclipse.datatools.connectivity.internal.ConnectionProfileMgmt.getStorageLocation(ConnectionProfileMgmt.java:1060)
at org.eclipse.datatools.connectivity.oda.profile.internal.OdaProfileFactory.defaultProfileStoreFile(OdaProfileFactory.java:170)
at org.eclipse.datatools.connectivity.oda.profile.OdaProfileExplorer.defaultProfileStoreFile(OdaProfileExplorer.java:138)
at org.eclipse.datatools.connectivity.oda.profile.OdaProfileExplorer.loadProfiles(OdaProfileExplorer.java:292)
at org.eclipse.datatools.connectivity.oda.profile.OdaProfileExplorer.getProfileByName(OdaProfileExplorer.java:537)
at org.eclipse.datatools.connectivity.oda.profile.provider.ProfilePropertyProviderImpl.getConnectionProfileImpl(ProfilePropertyProviderImpl.java:184)
at org.eclipse.datatools.connectivity.oda.profile.provider.ProfilePropertyProviderImpl.getDataSourceProperties(ProfilePropertyProviderImpl.java:64)
at org.eclipse.datatools.connectivity.oda.consumer.helper.ConnectionPropertyHandler.getEffectiveProperties(ConnectionPropertyHandler.java:123)
at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaConnection.getEffectiveProperties(OdaConnection.java:826)
at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaConnection.open(OdaConnection.java:240)
at org.eclipse.birt.data.engine.odaconsumer.ConnectionManager.openConnection(ConnectionManager.java:165)
at org.eclipse.birt.data.engine.executor.DataSource.newConnection(DataSource.java:224)
at org.eclipse.birt.data.engine.executor.DataSource.open(DataSource.java:212)
at org.eclipse.birt.data.engine.impl.DataSourceRuntime.openOdiDataSource(DataSourceRuntime.java:217)
at org.eclipse.birt.data.engine.impl.QueryExecutor.openDataSource(QueryExecutor.java:407)
at org.eclipse.birt.data.engine.impl.QueryExecutor.prepareExecution(QueryExecutor.java:317)
at org.eclipse.birt.data.engine.impl.PreparedQuery.doPrepare(PreparedQuery.java:455)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.produceQueryResults(PreparedDataSourceQuery.java:190)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.execute(PreparedDataSourceQuery.java:178)
at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery.execute(PreparedOdaDSQuery.java:145)
at org.eclipse.birt.report.data.adapter.impl.DataRequestSessionImpl.execute(DataRequestSessionImpl.java:624)
at org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:152)
at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:267)
at org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1939)
at org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80)
at org.eclipse.birt.report.engine.executor.TableItemExecutor.execute(TableItemExecutor.java:62)
at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)
at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34)
at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)
at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:92)
at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:100)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:180)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run    (RunAndRenderTask.java:77)

有没有人看到这个错误并能给我指出正确的方向?

这里我给你一个建议,让我免于痛苦: 安装BIRT插件后,只需使用“-clean”选项启动eclipse即可。

明确地说,我的项目是从BIRT maven依赖项构建的,因此不应该使用eclipse依赖项来运行(除了设计报告),但是。。。我想在某个地方发生了冲突。。。特别是使用org.eclipse.datatools.connectivity_1.2.4.v201202041105.jar

为了全面了解,您应该遵循迁移指南:

它有助于使用连接配置文件将数据源参数外部化。
因此,如果您直接在报表设计中定义JDBC参数,则不需要它。

当我遇到这个问题时,我尝试了两种方法。第一件事解决了这个错误,但接着我又遇到了下一个错误

我尝试的第一件事是将setenv.sh文件设置为具有以下行:
export CATALINA\u OPTS=“$CATALINA\u OPTS-Djava.io.tmpdir=/opt/local/share/tomcat/apache-tomcat-8.0.8/temp/tmpdir-Dorg.eclipse.datatools\u workspacepath=/opt/local/share/tomcat/apache-tomcat-8.0.8/temp/tmpdir/workspace\u dtp”

在我在本地tomcat服务器中创建了
tmpdir
workspace\u dtp
目录之后,这个解决方案就成功了。这是根据指导意见进行的

然而,我刚刚遇到了下一个错误,那是一个连接配置文件错误。如果你需要的话,我可以再调查一下。我知道如何复制这个问题

我尝试的第二件事最终完全解决了这个问题,与我们的报表设计器在报表设计过程中选择了错误类型的数据源有关。有关完整的故事,请参阅我在Eclipse BIRT论坛上的帖子:


基本上,当报表类型应设置为“JDBC数据源”时,它被设置为“查询生成器的JDBC数据库连接”。请参见参考图片:

我使用此编程方式初始化WorskSpace目录:

@Override
public void initializeEngine() throws BirtException {
    // define eclipse datatools workspace path (required)
    String workspacePath = setDataToolsWorkspacePath();

    // set configuration
    final EngineConfig config = new EngineConfig();
    config.setLogConfig(workspacePath, Level.WARNING);

    // config.setResourcePath(getSqlDriverClassJarPath());

    // startup OSGi framework
    Platform.startup(config); // really needed ?
    IReportEngineFactory factory = (IReportEngineFactory) Platform
            .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
    engine = factory.createReportEngine(config);
    engine.changeLogLevel(Level.WARNING);
}

private String setDataToolsWorkspacePath() {
    String workspacePath = System.getProperty(DATATOOLS_WORKSPACE_PATH);
    if (workspacePath == null) {
        workspacePath = FilenameUtils.concat(SystemUtils.getJavaIoTmpDir().getAbsolutePath(), "workspace_dtp");
        File workspaceDir = new File(workspacePath);
        if (!workspaceDir.exists()) {
            workspaceDir.mkdir();
        }
        if (!workspaceDir.canWrite()) {
            workspaceDir.setWritable(true);
        }
        System.setProperty(DATATOOLS_WORKSPACE_PATH, workspacePath);
    }
    return workspacePath;
}
我还需要以这种方式在运行时强制数据源参数:

private void generateReportOutput(InputStream reportDesignInStream, File outputFile, OUTPUT_FORMAT outputFormat,
        Map<PARAM, Object> params) throws EngineException, SemanticException {
    // Open a report design
    IReportRunnable design = engine.openReportDesign(reportDesignInStream);

    // Use data-source properties from persistence.xml
    forceDataSource(design);

    // Create RunAndRender task
    IRunAndRenderTask runTask = engine.createRunAndRenderTask(design);

    // Use data-source from JPA persistence context
    // forceDataSourceConnection(runTask);

    // Define report parameters
    defineReportParameters(runTask, params);

    // Set render options
    runTask.setRenderOption(getRenderOptions(outputFile, outputFormat, params));

    // Execute task
    runTask.run();
}

private void forceDataSource(IReportRunnable runableReport) throws SemanticException {
    DesignElementHandle designHandle = runableReport.getDesignHandle();

    Map<String, String> persistenceProperties = PersistenceUtils.getPersistenceProperties();
    String dsURL = persistenceProperties.get(AvailableSettings.JDBC_URL);
    String dsDatabase = StringUtils.substringAfterLast(dsURL, "/");
    String dsUser = persistenceProperties.get(AvailableSettings.JDBC_USER);
    String dsPass = persistenceProperties.get(AvailableSettings.JDBC_PASSWORD);
    String dsDriver = persistenceProperties.get(AvailableSettings.JDBC_DRIVER);

    SlotHandle dataSources = ((ReportDesignHandle) designHandle).getDataSources();
    int count = dataSources.getCount();
    for (int i = 0; i < count; i++) {
        DesignElementHandle dsHandle = dataSources.get(i);
        if (dsHandle != null && dsHandle instanceof OdaDataSourceHandle) {
            // replace connection properties from persistence.xml
            dsHandle.setProperty("databaseName", dsDatabase);
            dsHandle.setProperty("username", dsUser);
            dsHandle.setProperty("password", dsPass);
            dsHandle.setProperty("URL", dsURL);
            dsHandle.setProperty("driverClass", dsDriver);
            dsHandle.setProperty("jarList", getSqlDriverClassJarPath());
            // @SuppressWarnings("unchecked")
            // List<ExtendedProperty> privateProperties = (List<ExtendedProperty>) dsHandle
            // .getProperty("privateDriverProperties");
            // for (ExtendedProperty extProp : privateProperties) {
            // if ("odaUser".equals(extProp.getName())) {
            // extProp.setValue(dsUser);
            // }
            // }
        }
    }
}
private void generateReportOutput(InputStream reportDesignInStream、File outputFile、OUTPUT_格式outputFormat、,
映射参数)抛出EngineeException、SemanticException{
//打开报表设计
IReportRunnable design=engine.openReportDesign(reportDesignInStream);
//使用persistence.xml中的数据源属性
forceDataSource(设计);
//创建runandender任务
IRunAndRenderTask runTask=engine.createrunandendertask(设计);
//使用来自JPA持久性上下文的数据源
//forceDataSourceConnection(runTask);
//定义报表参数
defineReportParameters(runTask、params);
//设置渲染选项
setRenderOption(getRenderOptions(outputFile,outputFormat,params));
//执行任务
runTask.run();
}
私有void forceDataSource(IReportRunnable runableReport)抛出SemanticException{
DesignElementHandle designHandle=runableReport.getDesignHandle();
Map persistenceProperties=PersistenceUtils.getPersistenceProperties();
String dsURL=persistenceProperties.get(AvailableSettings.JDBC_URL);
字符串dsDatabase=StringUtils.substringAfterLast(dsURL,“/”);
字符串dsUser=persistenceProperties.get(AvailableSettings.JDBC\u USER);
字符串dsPass=persistenceProperties.get(可用设置.JDBC_密码);
字符串dsDriver=persistenceProperties.get(AvailableSettings.JDBC_驱动程序);
SlotHandle数据源=((ReportDesignHandle)designHandle).getDataSources();
int count=dataSources.getCount();
for(int i=0;i
我也有同样的问题


将数据源类型从“查询生成器的JDBC数据库连接”更改为“JDBC数据源”为我解决了这个问题。

我会看一看,但我没有使用3.7,因此没有迁移。我正在使用4.2,但将阅读更多关于连接配置文件的内容。您的问题是否已解决?。我也面临同样的问题,你能检查一下url@Prathyush吗?你可以用一段代码看到我的新答案,如果这可以帮助你绕过连接配置文件的限制(请参阅forceDataSource)