Has anyone added the Birt Library to a project's build path successfully?
I installed Birt in Eclipse using Help-->Install New Software and copy paste the link for Birt 4.2.2 from the official website. Birt was downloaded from the internet and a new perspective appeared, namely Report Design. Apart from it no Library, no nothing. So I designed my report and started writing Java code in order to do a PDF export of my report, as I found on the internet. I wrote the following:
// Export Birt report
String format = HTMLRenderOption.OUTPUT_FORMAT_PDF;
EngineConfig config = new EngineConfig( );
config.setEngineHome( "C:\\Tools\\Eclipse\\plugins\\org.eclipse.birt.report.viewer_4.2.2.v201302041142\\birt" );
HTMLEmitterConfig hc = new HTMLEmitterConfig( );
HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler( );
hc.setImageHandler( imageHandler );
config.setEmitterConfiguration( HTMLRenderOption.OUTPUT_FORMAT_HTML, hc );
ReportEngine engine = new ReportEngine( config );
IReportRunnable report = null;
String reportFilepath = "C:/Workspace/reports/new_report.rptdesign";
try {
report = engine.openReportDesign( reportFilepath );
}
catch ( EngineException e ) {
System.err.println( "Report " + reportFilepath + " not found!\n" );
engine.destroy( );
return;
}
IRunAndRenderTask task = engine.createRunAndRenderTask( report );
HTMLRenderOption options = new HTMLRenderOption( );
options.setOutputFormat( format );
options.setOutputFileName( "C:/Workspace/reports/output.pdf" );
task.setRenderOption( options );
task.setParameterValues( parametersMap );
try {
task.run( );
}
catch ( EngineException e1 ) {
System.err.println( "Report " + reportFilepath + " run failed.\n" );
System.err.println( e1.toString( ) );
}
engine.destroy( );
return;
Of course no Birt Library is set in my Build Path, so all Birt objects were red. I manually added all Birt jars that existed in Eclipse's plugins folder and all the reds disappeared. It seemed that everything was going great. When I run it I get:
java.lang.NoClassDefFoundError: org/eclipse/birt/report/engine/api/EngineException
while the org.eclipse.birt.report.engine.api package exists in my Build Path
and the EngineException.class exist in the package. I am feeling that there are jar files that I am missing.
I have searched for a solution in Birt home page and found nothing. Most tutorials have instructions regarding how to build a report. But nothing regarding how to get the library up and running with Java.
Is there a standard or automatic or official way to add Birt Library to Eclipse? It is made by Eclipse. It shouldn't be so difficult. Any help will be appreciated.
Have you read this page -> http://wiki.eclipse.org/Servlet_Example_(BIRT)_2.1
Maybe you can find some hints there.
Related
I'm integrating OpenSAML 3.3 in my application, and instead of hard-coding all the urls etc, I would like to be able to use the configuration XMLs.
I was given such an XML file for a adfs instance, it is 'FederationMetadata.xml'
This is the snippet I used to read it:
InitializationService.initialize();
FilesystemMetadataResolver idpMetaDataProvider = new FilesystemMetadataResolver( new File("/home/raudenaerde/sso/FederationMetadata.xml") );
idpMetaDataProvider.setRequireValidMetadata(true);
idpMetaDataProvider.setParserPool(new BasicParserPool());
idpMetaDataProvider.initialize();
However, this gave me this error:
> Exception in thread "main"
> net.shibboleth.utilities.java.support.component.ComponentInitializationException:
> Component identifier can not be null
Using an github project (https://github.com/coveo/saml-client) that uses OpenSAML 2.6.4 I had no problems reading it, but I'd like to stick with the newest version 3.3.
Am I missing some basic set-up?
There are 2 things that needed to be fixed:
In OpenSaml v3 many class instances are required to have an ID, setId(String) must be called before initialize()
The BasicParserPool needs to be initialized as well.
Complete working code:
InitializationService.initialize();
FilesystemMetadataResolver idpMetaDataProvider = new FilesystemMetadataResolver( new File( "/home/raudenaerde/sso/FederationMetadata.xml" ) );
idpMetaDataProvider.setRequireValidMetadata( true );
idpMetaDataProvider.setId( "myId" );
BasicParserPool pool = new BasicParserPool();
pool.initialize();
idpMetaDataProvider.setParserPool( pool );
idpMetaDataProvider.initialize();
for ( EntityDescriptor idpEntityDescriptor : idpMetaDataProvider )
{
System.out.println( idpEntityDescriptor.getID() );
for ( SingleSignOnService sss : idpEntityDescriptor.getIDPSSODescriptor( SAMLConstants.SAML20P_NS ).getSingleSignOnServices() )
{
if ( sss.getBinding().equals( SAMLConstants.SAML2_REDIRECT_BINDING_URI ) )
{
System.out.println( sss.getLocation() );
}
}
for ( ArtifactResolutionService ars : idpEntityDescriptor.getIDPSSODescriptor( SAMLConstants.SAML20P_NS ).getArtifactResolutionServices() )
{
if ( ars.getBinding().equals( SAMLConstants.SAML2_SOAP11_BINDING_URI ) )
{
System.out.println( ars.getLocation() );
}
}
}
I got error While running the jess in java program like
error: package jess does not exist
I don't know what and all packages to be included.
I have written code like this:
import jess.*;
public class ExQuery {
public static void main(String[] argv) throws JessException {
Rete engine = new Rete();
engine.batch("query.clp");
engine.reset();
QueryResult result =
engine.runQueryStar("search-by-name", new ValueVector().add("Smith"));
while (result.next()) {
System.out.println(result.getString("fn") + " " + result.getString("ln")
+ ", age" + result.getInt("age"));
}
}
}
Make sure you've imported the jess.jar librairy into your project.
Right click on project -> Properties -> Into Java Build Path -> Add external JARs
you need to select the jess.jar file into your Jess71p2 (or other version..) -> lib -> jess.jar
I have an application which deals with jdbc. It supposes to be used in any PC where there is JRE, but it does not suppose that use will use -cp command line or change his/her classpath variables. So the user has my application, JRE and a jdbc driver somewhere in file system. Now he or she enters a database connection information including path to jdbc driver jar and then make sql request. The problem is that I don't now how to make jdbc driver classes to be accessible in this application. The same way as the user explicitly add a driver to classpath.
I just altered part of the miks answer for your other posting.
Executing the following code got me a success.
import java.io.File;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
public class URLClassLoaderSample {
public static void main( String [] args ) throws Exception {
File f = new File( "/home/ravinder/Desktop/mysql-connector-java-5.1.18-bin.jar" );
URLClassLoader urlCl = new URLClassLoader( new URL[] { f.toURL() }, System.class.getClassLoader() );
Class mySqlDriver = urlCl.loadClass( "com.mysql.jdbc.Driver" );
System.out.println( mySqlDriver.newInstance() );
System.out.println( "Is this interface? = " + mySqlDriver.isInterface() );
Class interfaces[] = mySqlDriver.getInterfaces();
int i = 1;
for( Class _interface : interfaces ) {
System.out.println( "Implemented Interface Name " + ( i++ ) + " = " + _interface.getName() );
} // for(...)
Constructor constructors[] = mySqlDriver.getConstructors();
for( Constructor constructor : constructors ) {
System.out.println( "Constructor Name = " + constructor.getName() );
System.out.println( "Is Constructor Accessible? = " + constructor.isAccessible() );
} // for(...)
} // psvm(...)
} // class URLClassLoaderSample
Output seen is as follows:
com.mysql.jdbc.Driver#60aeb0
Is this interface? = false
Implemented Interface Name 1 = java.sql.Driver
Constructor Name = com.mysql.jdbc.Driver
Is Constructor Accessible? = false
And I don't understand what I should with log4jClass variable in my case *(com.mysql.jdbc.Driver)
Let me hope now you got it.
The best solution in this instance would be to distribute the required driver with your application and include either an executable wrapper or a shell script that sets the required variables accordingly. That allows the user to use it out of the box without having to mess with any complicated configuration and also doesn't require them to download any additional files.
Well, jdbc uses Class.forName("org.postgresql.Driver"); to load the driver. So once, you have the jar file, and have added it to the class-path, this part is easy. Just keep a hash of driver fqn classnames to jar file names. Or you can scan the jar for the Driver class.
Here's a convienent answer to how to add the jar file to the classpath once you find it.
I am trying hard to implement a charting extension to an app that i am developing : so my problem is that I have written some code (the boiler plate one) for doing this in BIRT.
At some place in the code, I have to link the dataset to a series and link the series to a seriesdefinition object which finally will be attached to the charts seriesDefinitions like this
RadarSeries radarSeries = RadarSeriesImpl.create();
radarSeries.setDataSet(numberDataValues);
radarSeries.setSeriesIdentifier("Number data values");
radarSeries.getLabel().setVisible(true);
where numberDataValues is an array of doubles. Then I create my seriesDefinition :
SeriesDefinition seriesDefinition = SeriesDefinitionImpl.create();
seriesDefinition.getSeriesPalette().shift(0);
But then, here comes the time when I have to LINK my radarSeries to the seriesDefinition like this :
seriesDefinition.getSeriesDefinitions().add(radarSeries);
THE PROBLEM : I don't have the getSeriesDefinitions() method when trying to call it from code (doing a Ctrl+Space in Eclipse).
Needless to say that I can't call the getSeriesDefinitions() method on myChart object :
myChart.getSeriesDefinitions().add(seriesDefinition);
FOR YOUR INFORMATION : I have included my birt jars manually in my local maven repository and the details of these dependencies are :
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>engineapi</artifactId>
<version>${birtVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>coreapi</artifactId>
<version>${birtVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>scriptapi</artifactId>
<version>${birtVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>chartengineapi</artifactId>
<version>${birtVersion}</version>
</dependency>
where ${birtVersion} = 2.6.2
here is a link to the official example of the 2.6.2 release of birt about RadarChart : Radar chart official release example
Can somebody help me ? I really can't believe I didn't found out how to do this in a 3days google search session : that not serious! ... given its popularity and its power, I think they should have invested more effort in the documentation ...
#Birt guyz (if any) > sorry to be so dramatic guys, but I really think that the doc side really sucks ... I hope to be able to help you on this (really, I do)
Here is the code :
public String drawChart() {
// Birt Vars
IDeviceRenderer iDeviceRenderer = null;
IDisplayServer iDisplayServer = null;
RunTimeContext context;
Chart chart = null;
// Birt Platform configuration
PlatformConfig platformConfig = new PlatformConfig();
platformConfig.setProperty("STANDALONE", true);
// Creating Chart Engine
ChartEngine chartEngine = ChartEngine.instance(platformConfig);
IGenerator iGenerator = chartEngine.getGenerator();
if(iGenerator == null)
System.out.println("IGenerator NULL");
else
System.out.println("IGenerator NOT NULL");
try {
// iDeviceRenderer = chartEngine.getRenderer("dv.PNG");
iDeviceRenderer = chartEngine.getRenderer("dv.GIF");
iDisplayServer = iDeviceRenderer.getDisplayServer();
} catch (Exception e) {
e.printStackTrace();
}
// Creating Chart
ChartWithoutAxes radarChart = ChartWithoutAxesImpl.create( );
radarChart.setDimension( ChartDimension.TWO_DIMENSIONAL_LITERAL );
radarChart.setType(Radar.TYPE_LITERAL); //$NON-NLS-1$
radarChart.setSubType( "Standard Radar Chart" ); //$NON-NLS-1$
// Plot
radarChart.setSeriesThickness( 10 );
// Legend
Legend lg = radarChart.getLegend( );
lg.getOutline( ).setVisible( true );
// Title
radarChart.getTitle( )
.getLabel( )
.getCaption( )
.setValue( "Radar Chart" );//$NON-NLS-1$
try {
if(radarChart != null)
System.out.println("RADAR CHART NOT NULL");
else
System.out.println("RADAR CHART NULL!!!");
// PREPARE PHASE
context = Generator.instance().prepare(radarChart, null, null, ULocale.getDefault());
if(context == null)
System.out.println("CONTEXT NULL ");
else
System.out.println("CONTEXT NOT NULL");
//BIND PHASE : fetch data from DB
NumberDataSet numberDataValues = NumberDataSetImpl.create( new double[]{
54, 21, 75, 91, 37
} );
// Radar series
RadarSeries radarSeries = RadarSeriesImpl.create();
radarSeries.setDataSet(numberDataValues);
radarSeries.setSeriesIdentifier("Number data values");
radarSeries.getLabel().setVisible(true);
SeriesDefinitionImpl seriesDefinition = (SeriesDefinitionImpl) SeriesDefinitionImpl.create();
seriesDefinition.getSeriesPalette().shift(0);
// ERROR HERE : can't call the method
seriesDefinition.getSeriesDefinitions()
// RENDERING PHASE
if(iDisplayServer == null)
System.out.println("DISPLAY SERVER NULL");
else
System.out.println("DISPLAY SERVER NOT NULL");
GeneratedChartState generatedChartState = iGenerator.build(iDisplayServer, radarChart, null, null, context);
iGenerator.render(iDeviceRenderer, generatedChartState);
} catch (Exception e) {
e.printStackTrace();
}
}
EDIT + SOLUTION
Sorry for the delay : I should have posted this answer earlier to mark this question as solved.
Just use the RCP report designer to create your report document. Copy ReportEngine/lib/*jars to your /WEB-INF/lib; also create a platform/ directory under WEB-INF/ and copy BIRT ReportEngine configuration/ and plugins/ directories under the newly created WEB-INF/platform/ folder. Now with the *.rptdesign file that you have created in your BIRT RCP designer tool, you will have to use the BIRT API which will allow you to interact with your report...
Sorry for the delay : I should have posted this answer earlier to mark this question as solved.
Just use the RCP report designer to create your report document.
Then copy ReportEngine/lib/*jars to your /WEB-INF/lib; also create a platform/ directory under WEB-INF/ and copy BIRT ReportEngine configuration/ and plugins/ directories under the newly created WEB-INF/platform/ folder.
Now with the *.rptdesign file that you have created in your BIRT RCP designer tool, you will have to use the BIRT API which will allow you to interact with your report...
There is an article in the Eclipse wiki how to configure user's p2 default repositories of an RCP application by adding a static conf file to your product:
Equinox/p2/Adding Self-Update to an RCP Application - Configuring the user's default repositories
I want to do the same programmatically in a Java class when the user changes some configuration details. I could not find appropriate p2 API documentation for that.
Use this solution for Eclipse 3.7 based applications:
final ProvisioningUI ui = ProvUIActivator.getDefault().getProvisioningUI();
IArtifactRepositoryManager artifactManager = ProvUI.getArtifactRepositoryManager(ui.getSession());
artifactManager.addRepository(new URI(UPDATE_SITE_URL);
IMetadataRepositoryManager metadataManager = ProvUI.getMetadataRepositoryManager(ui.getSession());
metadataManager.addRepository(new URI(UPDATE_SITE_URL);
For ProvUI and ProvisioningUI you have to import bundles org.eclipse.equinox.p2.ui and org.eclipse.equinox.p2.operations (among others).
I found a solution. It's easy - unfortunately there is no documentation...
// from bundle org.eclipse.equinox.p2.console
import org.eclipse.equinox.internal.p2.console.ProvisioningHelper;
URI repoUri = new URI(UPDATE_SITE_URL);
try {
ProvisioningHelper.addMetadataRepository(repoUri);
} catch( Exception e ) {
LOG.warn("Can not add update repository: " + repoUri);
}
try {
ProvisioningHelper.addArtifactRepository(repoUri);
} catch( Exception e ) {
LOG.warn("Can not add update repository: " + repoUri);
}
Furthermore you can add more than one repositories with ElementUtils and also you can sort them.
MetadataRepositoryElement[] element = new MetadataRepositoryElement[links.length];
for (int i = 0; i < links.length; i++) {
element[i] = new MetadataRepositoryElement(null, new URI(links[i]), true);
element[i].setNickname("Link-"+i);
}
ElementUtils.updateRepositoryUsingElements(element, null);
These links will be appeared alphabetically sorted.
This is high on the Google query for this issue, and there's still not a good way to do it published:
If anyone finds this page via Google as I did, I've solved this problem. You can use org.eclipse.equinox.internal.p2.ui.model.ElementUtils.updateRepositoryUsingElements to set the repositories programmatically. Full code can be found here.