Search code examples
javaapacheapache-poiclasspathjxls

Cannot load jxls transformer


What's wrong with my project. I've imported all the dependencies but it still outputs error :

Output errors

Here are the list dependencies I imported : Dependancies package image

And here is my test code :

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package brouillon;

import controllers.RetardJpaController;
import entites.Retard;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import javax.persistence.Persistence;
import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;

/**
 *
 * @author Vals
 */
public class Brouillon {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        RetardJpaController ctr = new RetardJpaController(Persistence.createEntityManagerFactory("BrouillonPU"));
        List<Retard> liste = ctr.findRetardEntities();
        try(InputStream is = Brouillon.class.getResourceAsStream("ressources/object_collection_template.xls")) {
            try (OutputStream os = new FileOutputStream("object_collection_output.xls")) {
                Context context = new Context();
                context.putVar("retards", liste);
                //JxlsHelper.getInstance().processTemplate(is, os, context);
                JxlsHelper jh = JxlsHelper.getInstance();
                jh.processTemplate(is, os, context);
            }
        }
    }

}

Solution

  • This doesn't look right to me:

        try(InputStream is = Brouillon.class.getResourceAsStream("ressources/object_collection_template.xls")) {
    

    Note the misspelling: "ressources". That's enough to do in the lookup. Try taking out that second 's' and see if it works.

    It might be worse than that. If resources is a code source, then its contents will be in the CLASSPATH, but the folder itself won't be. It that case you'd only need the file name.

    Try looking at the CLASSPATH you use at runtime and see what's in it. That'll make it clear.

    "I've imported all the dependencies" - this is your biggest problem. Most beginners and inexperienced programmers fall prey to that attitude of "I've done everything right - why is the computer persecuting me?" You'll get further faster if you adopt an attitude that begins and ends with "What have I done wrong?" and ruthlessly checks for mistakes by you.