0

I am reading Excel file using Apache POI, it is working fine in local machine (Standalone prog), but it is not running in server (IBM websphere). It's stopped working when it encounters to instantiate WorkBook.

Below jars are used.

commons-codec-1.5.jar poi-3.9.jar poi-examples-3.9.jar poi-ooxml-3.9.jar poi-ooxml-schemas-3.9.jar xmlbeans-2.6.0.jar

Below is my code:

    String mountInFilePath = "//XXXXX/YY/Foooo/folder/";
    File fileList = new File(mountInFilePath);
    File[] fileNames = fileList.listFiles();
    String inFileName = null;

    if(fileNames != null && fileNames.length > 1){
        throw new Exception("Multiple Files found in "+mountInFilePath+", Please place the latest one.");
    }else{
        System.out.println("getAbsolutePath: "+fileList.getAbsolutePath());
        for(File file : fileNames){
            System.out.println("New file path: "+file.getCanonicalPath());
            inFileName = file.getCanonicalPath();
        }
    }
    LOGGER.info("File: "+inFileName);
    if(inFileName != null){
        LOGGER.info("Inside IF cond...");
        System.out.println("Inside IF cond...");

        //Getting the workbook file
        LOGGER.info("After FileInputStream...");

        File chkAcc = new File(inFileName);
        if(chkAcc.canRead()){
            LOGGER.info("File Readable..");    //This is printed
        }else{
            LOGGER.info("Can not read file..");
        }
        Workbook workbook = WorkbookFactory.create(chkAcc);  //Stopped here
        //Iterating work sheet
        LOGGER.info("Iterating...");
        System.out.println("Iterating...");
halfer
  • 19,824
  • 17
  • 99
  • 186
Mr. SKS
  • 1
  • 1
  • 1
    Since your code is not complete I cannot see this but you must suppress errors somewhere or redirecting them into log files. `WorkbookFactory.create`throws exceptions if it fails. And running into an `OutOfMemoryError: GC overhead limit exceeded...` because of the size of the `Workbook` also should be thrown somewhere. Maybe there are log files you can have a look into? But `apache poi` version `3.9` is rather old. Why not using current version? – Axel Richter Oct 25 '18 at 07:04
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Oct 25 '18 at 07:13
  • @AxelRichter - This code is written inside try-catch block and the log is written for exceptions, also the file is very small in size. I was using poi 3.15 and got this issue, i have read from somewhere that one of the resolutions was to downgrade the version. – Mr. SKS Oct 25 '18 at 10:47
  • As a general rule, upgrading to the latest stable version (for subsequent bug fixes) is normally much better than downgrading to an older one with more unfixed bugs! – Gagravarr Oct 25 '18 at 12:36
  • You needs getting the reason why the code stops. So there is no other way than getting this information from an exception stacktrace or an error message. If your code is written inside try-catch block then make sure, the catch block not simply supresses all exceptions but shows or writes the exception's stacktraces somewhere. – Axel Richter Oct 26 '18 at 07:58
  • It's resolved now. I missed to add one dependency to pom.xml but it was in my build path. As Deepak Gunasekaran mention below, it resolved after adding that. Also i upgraded to 3.15 version. Thanks all for prompt help. – Mr. SKS Oct 26 '18 at 11:30
  • @halfer - I do not think I have mentioned such terms anywhere. – Mr. SKS Oct 26 '18 at 11:33
  • @Mr.SKS: they have now gone, I removed them. [See the revision history](https://stackoverflow.com/posts/52983083/revisions). – halfer Oct 26 '18 at 17:20

2 Answers2

0

Once Check if those dependency jar's are actually included in the final build or not (one which you deployed in the server). I faced this kind of issue in Weblogic server there i missed to include the jar while building the .ear file

  • "I faced this kind of issue in Weblogic server": Without any error thrown and without any error in the log files? Then the server is misconfigured. Errors **should** be visible somewhere. Maybe not for the public but at least for the admins in the log files. – Axel Richter Oct 25 '18 at 07:12
  • **Yes. Without throwing any exception**. The program stopped executing after that particular line of code. When i include the jarin my build.xml file, then the issue got fixed. – Deepak Gunasekaran Oct 25 '18 at 07:26
  • If it lacks a library then there should be a class not found error and this should be logged somewhere. As said simply throwing errors to nowhere is a misconfiguration in my opinion. – Axel Richter Oct 25 '18 at 07:37
  • Yeah as you said there may be misconfiguration . but the sad thing is no errors were thrown, the code simply stopped executing after that line, no logs were printed after that line. – Deepak Gunasekaran Oct 25 '18 at 07:42
  • @DeepakGunasekaran - Yes, have added to build path and put in lib folder for double sure. – Mr. SKS Oct 25 '18 at 10:49
  • Try printing the location of the jar from which that particular class is from. Then you may know if there is any jar conflicts. Refer the below link for getting the location of jar https://stackoverflow.com/questions/1983839/determine-which-jar-file-a-class-is-from – Deepak Gunasekaran Oct 25 '18 at 11:01
0

It's resolved now. I missed to add one dependency to pom.xml but it was in my build path. As Deepak Gunasekaran mentioned in an answer, it resolved after adding that. Also I upgraded to 3.15 version.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mr. SKS
  • 1
  • 1