Question

I created simple REST web app that would create Excel file and put into current directory. But somehow the generated excel is not in the directory. Actually it is not even being created.

The output "done" is shown in GlassFish server log so the process actually get to the end without any error. The only thing I am suspecting is the file path I'm specifying for "myExcelFileThatWouldNotShowUp".

I gave full path or relative path I can think of but Excel file is not still showing up. Interestingly, if I don't run this as web app (i.e. put the code in local main() function and run it, it works) Thus I think something to do with GlassFish but can't really figure out :(

  • GlassFish v3
  • REST / JAX-RS
  • Excella framework to generate Excel spreadsheet from template (myTemplate.xls)

Code snippet

    @Path("horizontalProcess")
    @GET
    @Produces("application/xml")
    public String getProcessHorizontally() {

        try {
            URL templateFileUrl = this.getClass().getResource("myTemplate.xls");

            //  getPath() outputs... 
            //  /C:/Users/m-takayashiki/Documents/NetBeansProjects/KogaAlpha/build/web/WEB-INF/classes/local/test/jaxrs/myTemplate.xls
            System.out.println(templateFileUrl.getPath());

            String templateFilePath = URLDecoder.decode(templateFileUrl.getPath(), "UTF-8");

            //specify output path which is current dir and should create
            //myExcelFileThatWouldNotShowup.xls but it is not..
            String outputFileDir = "myExcelFileThatWouldNotShowUp";

            //<<template path>>,  <<output path>>,  <<file format>>
            ReportBook outputBook = new ReportBook(templateFilePath, outputFileDir, ExcelExporter.FORMAT_TYPE);

            ReportSheet outputSheet = new ReportSheet("myExcelSheet");
            outputBook.addReportSheet(outputSheet);

            //this is printed out so process actually gets here
            System.out.println("done!!");
        }
        catch(Exception e) {
            System.out.println(e);
        }


        return null;
    }//end method
Was it helpful?

Solution

That's why one shouldn't code when tired/overtime worked....

I forgot to add 2 lines of code at the end that actually generate the excel... cost me couple hours of debugging.. (don't ask how i was debugging :p

ReportProcessor reportProcessor = new ReportProcessor();
 reportProcessor.process(outputBook);

Btw, generated file are stored in the dir below as default if you don't specify.

 //C:\Users\m-takayashiki\.netbeans\6.9\config\GF3\domain1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top