Create a Jasper report from a standalone Java application

Started by arch.model.user, April 06, 2019, 02:39:30 AM

Previous topic - Next topic

arch.model.user

Hello all,

Our main goal is to create a Jasper report of an ArchimateModel from a standalone Java program. The idea is to create standardized views like the layered view, service realization, application usage, etc.. programmatically (as IArchimateDiagramModel objects) so that they look consistent across all the apps/services in our portfolio and also make the reports/models automatically updated when the information changes.

I started looking at the Archimate tool source code and noticed that the jasper report of ARCHISURANCE test model is created/exported in JasperReportsExporterTests.java using JasperReportsExporter.

I set up Eclipse as documented and when I run 'Maven install' on a pom.xml of com.archimatetool.jasperreports.tests project in Eclipse, all the tests are PASSED and the Jasper reports are generated. Cool  :)
But when I tried to create/export a Jasper report (same piece of code, similarly how it is done in JasperReportsExporterTests) from a standalone program in Eclipse, I am getting Null pointer exceptions.

What I observed when I execute as a standalone java process is -

Platform.isRunning() returns false.
Platform.getBundle(JasperReportsPlugin.PLUGIN_ID) is null.
Platform.getExtensionRegistry() returns null.
RegistryProviderFactory.getDefault() returns null.
PlatformActivator.getContext() returns null.

I believe the Plugins and the associated bundles are not loaded properly and the Platform is not set up correctly or something to do with OSGi bundles when I execute as a standalone java process.

I have setup the following arguments explicitly for standalone Java process.
-Dosgi.noShutdown=false -Dosgi.os=macosx -Dosgi.ws=cocoa -Dosgi.arch=x86_64 -XstartOnFirstThread -Dosgi.clean=true

I have also added all the Eclipse jars (related to swt, ui, zest, jdt, equinox, emf, ..) to the Classpath of a Java process as external jars.

But no luck. So the question is, How do I make sure the Platform loads correctly for a Standalone Java process (Should run in either in Eclipse or external)?

Any pointers would be greatly appreciated.

Thank you!

Phil Beauvoir

It really needs to run with all Eclipse dependencies loaded, and there are many. Even when running the tests, the Platform is loaded.

Instead you could run Jasper from the command line.

See https://github.com/archimatetool/archi/wiki/Archi-Command-Line-Interface
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

arch.model.user

Hi Phil,

Thank you for your response.

Based on the documentation I understand that I need to provide model (.archimate) file to CLI so that it exports Jasper report for it.
But my requirement is, creating IArchimateModel object programmatically (based on the information we get from other sources) and export Jasper reports out of that model. 
Is it possible?  Or am I missing something?

Also. I am trying to run CLI on my mac using the following command
Archi.app/Contents/MacOS/launcher/Archi -application com.archimatetool.commandline.app -consoleLog -nosplash --help

But getting the following error.

java.lang.RuntimeException: Application "com.archimatetool.commandline.app" could not be found in the registry. The applications available are: org.eclipse.help.base.infocenterApplication, org.eclipse.help.base.helpApplication, org.eclipse.help.base.indexTool, org.eclipse.equinox.app.error, com.archimatetool.editor.app, org.eclipse.e4.ui.workbench.swt.E4Application, org.eclipse.e4.ui.workbench.swt.GenTopic.

Any help?
Thank you.

Phil Beauvoir

#3
The wiki at https://github.com/archimatetool/archi/wiki/Archi-Command-Line-Interface says:

"Since version 4.2, some Archi functions can be invoked from the Archi Command Line Interface"

And the command line for Mac should be:

Archi.app/Contents/MacOS/Archi -application com.archimatetool.commandline.app -consoleLog -nosplash --help

To create an Archi model programmatically you could do that using jArchi, the scripting language.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

arch.model.user

#4
My bad, downloaded version 4.4 and able to launch ACLI. Thank you!

Reg. building models pragmatically - Our goal is to automate the creation of Arch model/views and Jasper reports, without explicitly using Archi UI.

Since we have a Java backend app (not a web app) already, We would like to leverage it (maintenance and DB integration perspective) rather introduce another approach like JArchi.

So, the possibilities seem are -

Creating archimate model programmatically (in java) and Call the ACLI from the same java process to generate Jasper.

Or try to load all the platform required plugins/features at startup of java process and use JasperReportsExporter to create jasper (I know you mentioned that it could be a lot of work to load/launch startup jars)

Do you see any issues on productionalizing any one of these approaches Or do you suggest an alternative?

Thanks so much for your time and help.

Phil Beauvoir

For the Jasper Reports to generate images, text, and the information in a model you have to use most of the Archi code stack and all dependencies. So "without explicitly using Archi" is not possible. You can however run it in "headless" mode which is how JUnit tests and the ACLI do it.

The ACLI calls a "headless" application - com.archimatetool.commandline.app which calls class com.archimatetool.commandline.CentralScrutinizer so you could write your own headless application class, register it as a plugin and work from there.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

arch.model.user