Apache POI error "hasPOIFSHeader" NoSuchMethodError

2,321 views
Skip to first unread message

Andy Jarrett

unread,
Dec 28, 2010, 5:22:17 AM12/28/10
to ra...@googlegroups.com
Hi

I am having trouble with Railo 3.2 and the POI library (which I am creating an extension provider for). When I try the following i get the error java.lang.NoSuchMethodError for org.apache.poi.poifs.filesystem.POIFSFileSystem.hasPOIFSHeader(Ljava/io/InputStream;)Z

<cfset src = "/Users/andyjarrett/Documents/workspace/railo_extensions/railo_extension_cfpoi/webroot/courses.xls" />

<cfset inputStream = CreateObject("java", "java.io.FileInputStream").init(src) />

<cfset workbookFactory = CreateObject("java", "org.apache.poi.ss.usermodel.WorkbookFactory").init() />

<cfset workbook = workbookFactory.create(inputStream) />


I've also created a simple Java app to test (using the same jars) and this works fine. 


import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStream;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

import org.apache.poi.ss.usermodel.Workbook;

import org.apache.poi.ss.usermodel.WorkbookFactory;


public class scribble {

public static void main(String[] args) throws InvalidFormatException, IOException {

    InputStream inp = new FileInputStream("/Users/andyjarrett/Documents/workspace/railo_extensions/railo_extension_cfpoi/webroot/courses.xls");

    Workbook wb = WorkbookFactory.create(inp);

    System.out.println(wb.getNumberOfSheets());

}

}


Its probably more to do with my understanding of the POI library but was wondering if anyone else can spot my error?


Regards, 


Andy Jarrett

www.andyjarrett.co.uk/blog

Andy Jarrett

unread,
Dec 28, 2010, 5:40:42 AM12/28/10
to ra...@googlegroups.com
To answer my own problem the issue is because of the apache-poi-tm-extractors.jar already used by Railo.

Is there any way I can either update this jar or for my extension make sure to look at POI files I am supplying? 

Cheers,

Andy Jarrett

Todd Rafferty

unread,
Dec 28, 2010, 7:15:18 AM12/28/10
to ra...@googlegroups.com
You could use createObject()'s java loader or the <cfadmin> tag to update the jar files. I think Micha is the best person for answering this question though.
--
~Todd Rafferty ** Volunteer Railo Open Source Community Manager ** http://getrailo.org/

Andy Jarrett

unread,
Dec 28, 2010, 12:21:54 PM12/28/10
to ra...@googlegroups.com
Cheers Todd ... totally forgot about that. I'll give it a go and see how I get on

Andy Jarrett

unread,
Dec 28, 2010, 1:02:09 PM12/28/10
to ra...@googlegroups.com
Quick feedback .. that didn't work either.

I changed the createObject to

<cfset variables._poiPath = expandPath('{railo-web-directory}'&'/lib/poi-3.7-20101029.jar') />
<cfset var workbookFactory = CreateObject("java", "org.apache.poi.ss.usermodel.WorkbookFactory", variables._poiPath).init() />

and I get the same issue. It seems that I (probably quite obviously) cannot load another POI lib


Todd Rafferty

unread,
Dec 28, 2010, 2:07:17 PM12/28/10
to ra...@googlegroups.com
You may have to wait for Micha's response on this then. I think this week is going to be slow considering we're in between holidays. Bear with us and I'll make sure this is seen by someone.

Andy Jarrett

unread,
Dec 28, 2010, 4:12:20 PM12/28/10
to ra...@googlegroups.com
no worries.

Im thinking I might just make it available as an alpha this week so at least other people can play around with it.


Andy Jarrett
www.andyjarrett.com
www.linkedin.com/in/andyjarrett

Ξ Please think before you print Ξ

Michael Offner

unread,
Dec 29, 2010, 2:23:24 AM12/29/10
to ra...@googlegroups.com
Every class is loaded by a classloader and classloaders in java are
organized in a tree. When you "ask" a classloader for a class the
classloader always first check the parent classloader for this class
before loading it. To make sure classes are unique and seen for most
classloaders.
To "break" this you have to make sure the classloader you are using is
not connected to the classloader loading the jars in the lib
directory, what is equal to the system classloader in most cases. Load
your classes by a urlclassloader and do not define the system
classloader in the constructor. Then add your jars as a URL.

/micha

2010/12/28, Andy Jarrett <ma...@andyjarrett.co.uk>:


> no worries.
>
> Im thinking I might just make it available as an alpha this week so at least
> other people can play around with it.
>
>
> Andy Jarrett
> www.andyjarrett.com
> www.linkedin.com/in/andyjarrett
>

> *Ξ Please think before you print Ξ*

James Holmes

unread,
Dec 29, 2010, 3:34:57 AM12/29/10
to ra...@googlegroups.com
Try JavaLoader.
--
WSS4CF - WS-Security framework for CF
http://wss4cf.riaforge.org/

Andy Jarrett

unread,
Dec 29, 2010, 8:17:05 PM12/29/10
to ra...@googlegroups.com
Ok

I've tried using Javaloader but I am now seeing java heap space errors :(

I am only getting this when loading all 3 paths together. I know I can adjust my setting but I want this to work as simply as possible.

<cfscript>

//create the loader

local.paths = arrayNew(1);

// This points to the jar we want to load. Could also load a directory of .class files

local.paths[1] = expandPath('{railo-web-directory}'&'/lib/poi-3.7-20101029.jar');

local.paths[2] = expandPath('{railo-web-directory}'&'/lib/poi-ooxml-3.7-20101029.jar');

local.paths[3] = expandPath('{railo-web-directory}'&'/lib/poi-ooxml-schemas-3.7-20101029.jar');


if( NOT structKeyExists( server, "_loader")){

server._loader = createObject("component", "javaloader.JavaLoader").init( local.paths );

}

//at this stage we only have access to the class, but we don't have an instance

var classInstance = server._loader.create( arguments.javaclass);

</cfscript>


Just looking for help/guidance on the best way to use an updated POI lib. It is 1.15am so I might be missing something simple?

Cheers,

Ξ Please think before you print Ξ


Andy Jarrett

unread,
Dec 30, 2010, 2:58:39 AM12/30/10
to ra...@googlegroups.com
I've managed to resolve my Java heap error for now by setting the source as trusted which prevents it from always being recompiled and loaded


Andy Jarrett
www.andyjarrett.com
www.linkedin.com/in/andyjarrett

Ξ Please think before you print Ξ


2010/12/30 Andy Jarrett <ma...@andyjarrett.co.uk>

Michael Offner

unread,
Dec 30, 2010, 3:07:58 AM12/30/10
to ra...@googlegroups.com
I'm not to familiar with javaloader, but I think it is not written to
break the classloader rules, but you have to break them (see prior
mail)!

/micha

2010/12/30, Andy Jarrett <ma...@andyjarrett.co.uk>:


> I've managed to resolve my Java heap error for now by setting the source as
> trusted which prevents it from always being recompiled and loaded
>
>
> Andy Jarrett
> www.andyjarrett.com
> www.linkedin.com/in/andyjarrett
>

> *Ξ Please think before you print Ξ*

>> *Ξ Please think before you print Ξ*

Andy Jarrett

unread,
Dec 30, 2010, 5:08:35 AM12/30/10
to ra...@googlegroups.com
Javaloader gives you the option to Load the CFML class path which I have set to false.

I'm hopefully going to have it ready for first wave testing over the next couple of days so hopefully it can be picked apart a bit better then :D


Andy Jarrett
http://about.me/andyjarrett

2010/12/30 Michael Offner <mic...@getrailo.com>
Reply all
Reply to author
Forward
0 new messages