By alexismp on août 27, 2007
I recently got a request from a user trying to run the code from this web developerWorks article on using JasperReports and Velocity with the IBM stack (RAD, WebSphere, DB2). So these are the short instructions on how to (slightly) adapt it to the Open Source NetBeans/GlassFish/JavaDB stack:
• Create and populate the database
You can do this using the command-line using ij but NetBeans has a nice visual tool all we need.
- Make sure you have the Java DB Installation and Database Location set properly (Tools>JavaDB>Settings).
- Create a database called
'reportdb' with any user/password you'd like (just remember them...)
- Connect to the newly created database from the "Databases" node in the "Services" tab ("Runtime" in NetBeans 5.5.x)
- Create the tables and populate them by copy/pasting the SQL code from
create-db.sql and simply removing the
connect first two instructions as well as the closing
• Create the DataSource
From the GlassFish admin console, navigate to Resources>JDBC>Connection Pools to create a new pool with the following attributes:
- JavaDB driver
reportdb database name
- whatever the user/password you used to create the database.
- remove the
At this point you can ping the connection database to make sure all is ok. The JDBC Resource can then easily be created for this pool with the JNDI name
"jdbc/reportDB" as specified in the article.
The alternate approach is to use the following commands:
asadmin create-jdbc-connection-pool and
asadmin create-jdbc-resource .
• Deploy and run the application
Deploying the application can be done using the web admin tool,
asadmin deploy, or simply by dropping the EAR archive file in the
domains/domain1/autodeploy directory. No change is needed for this archive. All the IBM-specific content is safely ignored by GlassFish. Since there is no explicit context-path specified in the
web.xml from the WAR file, the application is then available from http://localhost:8080/JReportsWEB/
Note that deploying an EAR archive containing a WAR file will not have it (the war file) appear under the Web Application section. This is by design (a feature, not a bug). You can see the war file as an EAR sub component in the admin UI and the content of its
web.xml in the associated "descriptor" tab.
I'm not sure why the sample code from the article is packaged as an EAR file and not a simpler WAR archive. You can also manually extract the WAR file and deploy it. This developerWorks article isn't particularly new but it's interesting the see how easily this all works in a second-generation Java EE 5 application server with no modification.
You can go one step further with the NetBeans Jarvis module (discussed here). This article on JasperReports in NetBeans is probably also of interest.
JasperReports (now in version 2.0) and GlassFish stories are here and a book for "Java EE 5 Development using GlassFish Application Server" is also on its way.