Posts

Showing posts from September, 2011

Using the Crystal Reports Java API to generate PDF

I recently had to investigate how to generate a PDF from a Crystal Report created by another team. Without knowing anything about Crystal Reports, I had to google around for information and piece it all together. It turns out to be really simple once you know how. We were using Business Objects 4.0, and probably the most important thing was to get the Java library - download 'SAP Crystal Reports for Java runtime components - Java Reporting Component (JRC)' from http://www.businessobjects.com/campaigns/forms/downloads/crystal/eclipse/datasave.asp There are a lot of samples on the web to look at - you might find something to help here: http://wiki.sdn.sap.com/wiki/display/BOBJ/Java+Reporting+Component++SDK+Samples A good example to start with is “JRC EXPORT REPORT”: http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40d580ce-bd66-2b10-95b0-cc4d3f2dcaef If you have an RPT file, the java to generate the report is relatively simple - : ReportClientDocument reportClie

Easy classpaths with Java 6

Back in the day it used to be a bit more difficult than it is now to dynamically generate your java application classpath - you'd have to write a script to loop over all the jar files in a directory, appending them to your classpath variable - like this . Since Java 6 though, its been a lot easier - you can use wildcards to specify all jars in a directory. See the "Understanding class path wildcards" in the Java SE 6 documentation . Now its as simple as: java -cp /my/lib/dir/* MyClass Simple! As it should be!

Turning off JDK logging

I've been developing a simple little command line application and one of the libraries I'm using seems to log debug information to the console. To clean up the console output, I had to turn off the JDK by using: LogManager.getLogManager().reset(); This seemed to do the trick for me, but it sounds like in some cases you may need to go a bit further and turn off logging at the global logger level: LogManager.getLogManager().reset(); Logger globalLogger = Logger.getLogger(java.util.logging.Logger.GLOBAL_LOGGER_NAME); globalLogger.setLevel(java.util.logging.Level.OFF);

JUnit parameterized test with Spring autowiring AND transactions

I've been writing JUnit Parameterized tests (a nice intro here - also see Theories ) to do some data driven API testing. Now, when introducing Spring into the mix there are a couple of extra things to do . I came unstuck though because I was trying to do Transactional tests - since I'm now using @RunWith(Parameterized.class) and setting up my Spring TestContextManager manually the @Transaction annotations caused an exception: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given I couldn't find any built in solution, so I've gone with manual transaction management in my test, using doInTransaction: @RunWith(Parameterized.class) @ContextConfiguration(locations = "classpath*:/testContext.xml") public class MyTest { @Autowired PlatformTransactionManager transactionManager; private TestContextManager testContextManager; public MyTest (... parameters for test) { // store parameters in instance v