I have inherited a legacy Java application which has been packaged in a JAR file for execution by our users. The application uses an XML file to define the layout of a report that is produced through the application using JFreeReport. I've now been asked to "tweak" the report so that one of the fields prints slightly higher than it does currently, but this "simple" task is proving too much for me right now.
Now, let me start by saying that I primarily do my programming in VB.NET and do not have any experience programming in Java. I can usually read through the code and decipher it well enough to figure out what it's doing, and sometimes even "translate" it, but I've never actually written or compiled anything Java related (save some JavaScript on a Web page that I copied and pasted). It took me a lot of research to actually find out how to access and modify the contents of the JAR file, and now I'm stuck trying to make what should be a simple change to a report definition.
Here's what I have done:
- I've taken the original JAR file and extracted the XML definition file using the command line (jar xvf myapp.jar myapp/rptdef.xml)
- I modify the XML file, save it and update the JAR with the changed file, again using the command line (jar vfu myapp.jar myapp/)
Everything seems to be successful, but when I run the application with the modified XML file, the report will not come up at all. At first, I thought my editor might be "messing" with the file in a way that was causing it to break the report (like adding a BOM, or something stupid), but I tried a couple of things that ruled that out:
- Saved the XML file without making any changes and updated the JAR - the report works.
- Made a change to the XML file, saved it and updated the JAR - the report fails.
- Changed the XML file back, saved it and updated the JAR - the report works again.
It appears that something else might be tied to the report definition, but I don't know what it could possibly be. For completeness sake, here's the bit of code that (I believe) is producing and displaying the report:
    protected void attemptPreview() {      final URL in = getClass().getResource("/myapp/rptdef.xml");        if (in == null) {        System.out.println("No XML");      }      final JFreeReport report;      try {        report = parseReport(in);        report.setData(createData());  //      report.getGroupCount()        final URL imageURL = getClass().getResource("/myapp/myicon.jpg");        final Image image = Toolkit.getDefaultToolkit().createImage(imageURL);         final WaitingImageObserver obs = new WaitingImageObserver(image);        obs.waitImageLoaded();        report.setProperty("logo", image);        report.setPropertyMarked("logo", true);      }      catch (Exception ex) {   //        showExceptionDialog("report.definitionfailure", ex);   System.out.println("Err1");        return;      }        try {        final PreviewFrame frame = new PreviewFrame(report);          frame.getBase().setToolbarFloatable(true);        frame.pack();        RefineryUtilities.positionFrameRandomly(frame);        frame.setVisible(true);        frame.requestFocus();    //      Frame1.statusBar.setText(frame.getComponent(1).getName());      }      catch (ReportProcessingException rpe) {        //   showExceptionDialog("report.previewfailure", rpe);  System.out.println("Err2");      }    }      private JFreeReport parseReport(final URL templateURL) {        JFreeReport result = null;      final ReportGenerator generator = ReportGenerator.getInstance();      try {        result = generator.parseReport(templateURL);      }      catch (Exception e) {        Log.error("Failed to parse the report definition", e);      }      return result;      }      For reference, here's a sample from the XML file of what I'm attempting to change:
  <string-field x="15" y="110" width="400" height="10" alignment="left" fontsize="10" fieldname="displaytotal"/>  <number-field x="500" y="110" width="100" height="10" alignment="left" format="$###,###.00" fieldname="numerictotal"/>      All I want to do is move the displaytotal and numerictotal fields up just a few points, so I figured I should change the y value in each of these elements to a smaller amount (say, 100). But, as I said above, as soon as I change any of the y values in the definition, the report fails to load. I change them back, and voila, everything goes back to normal.
As you can see in the Java code, there isn't really any error handling to speak of (at least none that produces readable output anywhere I can find). I don't know if there's an exception being thrown somewhere, or if there's some other issue going on. Since I haven't gotten to the point in my research on how to actually compile Java code (and honestly, I'm a little afraid to break something else at this point), I can't really add any "better" error handling, although that would be tremendously helpful.
Does anyone have any suggestions as to why this is happening, and what I might be able to do to resolve it? Thank you so much.
No comments:
Post a Comment