Workarounds for using apache poi 3.9 with JDK 4

2019-08-16 22:22发布

问题:

This is a follow up question here . I just found this caption in Apache POI website.

POI 3.5 and later requires the JDK version 1.5 or later. Versions prior to 3.5 require JDK 1.4+

Clearly, that's the reason I can't build my Java program. I would just like to know if there are any workarounds where I can successfully build my project in Ant using my current settings.

Settings

  • Apache POI - 3.9
  • JDK - 1.4.2 (4.0)

Any advice, tips, or hacks are welcome. Thanks in advance!

回答1:

Java 1.4 is pretty old now - it was released in 2002 so over 10 years ago. Regular support ended in 2008, so I dread to think how much you're having to pay Oracle for extended support for it... If possible divert some of that cash to an upgrade project!

The last version of Apache POI to run on Java 1.4 was POI 3.2, released in October 2008. Source and binary packages of it are available from the Apache dist archive. There are two main snags with using POI 3.2 today, the first is that it only supports the binary file formats. It does not support the OOXML formats such as .xlsx, .pptx, .docx. Support for those (via XSLF, XSSF and XWPF) was only introduced with POI 3.5, and required the bump to Java 5 as the minimum. The second issue is you'll be missing out on 5 years of bug fixes and new features, of which there have been a lot!

It's been a few years since anyone asked about newer versions of Apache POI on old JDKs (everyone else has managed to upgrade to something with normal support available!). When people were asking, a common answer was to try Retroweaver, which should let you load and run JDK 5 code on JDK 1.4. I've not tried it myself, but people given that answer seemed to be happy so I assume it'll do the trick...

(Converting POI 3.9 to run on JDK 1.4 would be a lot of work for you. Since the 3.2 days, most of the new code has used generics, lots of old code has been greatly tidied up and simplified by moving to generics, I think there's the odd bit of varags, something about date formatters rings a bell, and there's all the XML stuff. It could be done, but it won't be quick)



回答2:

I guess this is very difficult. Just take an example=> suppose POI 3.9 is using feature of Generics or varargs of jdk 1.5, then how could you compile it with jdk 1.4. I suggest you either downgrade your POI version lower or upgrade your jdk version higher.

Edit: Add maven dependencies add support for POI 3.2 like below code

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.2-FINAL</version>
</dependency>


回答3:

I used Poi 3.8 migrated to jdk 1.4. It works :-)