Archive for January, 2010

WritableFont doesn’t like to be static!

While using the tool JExcelAPI within my Java application to generate Excel spreadsheets, I got the following exception:

java.lang.ArrayIndexOutOfBoundsException: 5
	at jxl.biff.IndexMapping.getNewIndex(IndexMapping.java:68)
	at jxl.biff.FormattingRecords.rationalize(FormattingRecords.java:388)
	at jxl.write.biff.WritableWorkbookImpl.rationalize(WritableWorkbookImpl.java:988)
	at jxl.write.biff.WritableWorkbookImpl.write(WritableWorkbookImpl.java:692)
	...

It appears that this exception occurs only when you try to generate more than one Excel spreadsheet! How strange is that! ๐Ÿ˜ฏ
After a bit of investigation, it seems that the problem comes from the use of the static modifier with a jxl.write.WritableFont variable.

I unfortunately don’t have the time to check the JExcelAPI code source to understand the root cause.
So my advice would be: “if you get EXACTLY the same stack trace, simply delete any static modifier you used with the WritableFont variables”. ๐Ÿ™‚

, , , , ,

8 Comments

Deploy your app to the root context

This is an easy trick which I am sure most of you already know.

Let’s take a Java application called MyAddressBook. Its generated war file could be called myaddressbook.war.

By default, when you deploy this web application to Tomcat, the URL to access it will be http://localhost:8080/myaddressbook/. And if you point a domain name such as ‘addressbook.com’ to this server, the URL would be http://addressbook.com/myaddressbook/.

I don’t know for you but I don’t like to systematically have the subfolder ‘myaddressbook’ after my domain. But maybe I am too picky! ๐Ÿ˜‰

The idea is to deploy our application in the Tomcat root context.
You have two ways of doing this:

  • Define a ROOT.xml file in your conf/Catalina/localhost folder, or;
  • Rename your war file to ROOT.war.

Note that the case is important, it has to be ROOT in UPPERCASE! ๐Ÿ™‚

Once this is done, you will be able to call your application via the URL http://localhost:8080/
or http://addressbook.com/. Way better! ๐Ÿ˜Ž

, ,

No Comments