简体   繁体   中英

“The import com.lowagie cannot be resolved ” (HYBRIS)

package de.hybris.training.core.job;

        import com.lowagie.text.Document;

        import com.lowagie.text.Phrase;

        import com.lowagie.text.pdf.PdfPTable;
        import com.lowagie.text.pdf.PdfWriter;
        import de.hybris.platform.cronjob.enums.CronJobResult;
        import de.hybris.platform.cronjob.enums.CronJobStatus;
        import de.hybris.platform.servicelayer.cronjob.AbstractJobPerformable;
        import de.hybris.platform.servicelayer.cronjob.PerformResult;

        import de.hybris.training.core.facade.impl.TotalCustomerFacadeImpl;
        import de.hybris.training.core.model.UsersFindCronJobModel;

        import java.util.List;


        import java.awt.*;
        import java.io.File;

        import java.io.FileOutputStream;



public class UsersFindJob extends AbstractJobPerformable<UsersFindCronJobModel> {

        private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UsersFindJob.class);
        TotalCustomerFacadeImpl totalCustomerFacade = new TotalCustomerFacadeImpl() ;




        @Override
        public PerformResult perform(UsersFindCronJobModel cronJobModel) {

                try {

                        // Retrieve firstName from the cronJob
                        String firstName = cronJobModel.getFirstName();

                        // Display Hello firstName
                        LOG.info("**********************************");
                        LOG.info("**********************************");
                        LOG.info("***********************************");LOG.info("**********************************");
                        LOG.info("***********************************");LOG.info("**********************************");
                        LOG.info("***********************************");LOG.info("**********************************");
                        LOG.info("***********************************");LOG.info("**********************************");
                        LOG.info("***********************************");LOG.info("**********************************");
                        LOG.info("***********************************");
                        LOG.info("Hello " + firstName);
                        LOG.info("**********************************");
                        LOG.info("**********************************");
                        LOG.info("**********************************");
                        LOG.info("***********************************");LOG.info("**********************************");
                        LOG.info("***********************************");LOG.info("**********************************");
                        LOG.info("***********************************");LOG.info("**********************************");
                        LOG.info("***********************************");

                        createSamplePDF( totalCustomerFacade.findCustomerContainingName(firstName));

                        // In case of success return result: SUCCESS and status: FINISHED
                        return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);

                } catch(Exception e) {

                        // In case of exception return result: ERROR and status: ABORTED
                        return new PerformResult(CronJobResult.ERROR, CronJobStatus.ABORTED);

                }
        }

        public static void createSamplePDF(List<String> firstNames) throws Exception{





                Document documento = new Document();
                //Create new File
                File file = new File("C:/newFileName.pdf");
                file.createNewFile();
                FileOutputStream fop = new FileOutputStream(file);
                PdfWriter.getInstance(documento, fop);
                documento.open();
                //Fonts
                Font fontHead = new Font(Font.DIALOG, 15, Font.BOLD);
                Font fontBody = new Font(Font.DIALOG, 12, Font.BOLD);


                //Tabla for body
                PdfPTable tabla = new PdfPTable(firstNames.size());
                for (int i = 0; i < firstNames.size(); i++) {

                                tabla.addCell(new Phrase(firstNames.get(i)));
                }

                documento.add(tabla);
                documento.close();
                fop.flush();
                fop.close();

        }
        }

this is my class. Intellij shows no error but when i make ant clean all, those come:

[yjavac] 1. ERROR in C:\\HYBRISCOMM6600P\\hybris\\bin\\custom\\training\\trainingcore\\src\\de\\hybris\\training\\core\\job\\UsersFindJob.java (at line 3)
[yjavac] import com.lowagie.text.Document;
[yjavac] ^^^^^^^^^^^
[yjavac] The import com.lowagie cannot be resolved
[yjavac] ----------
[yjavac] 2. ERROR in C:\\HYBRISCOMM6600P\\hybris\\bin\\custom\\training\\trainingcore\\src\\de\\hybris\\training\\core\\job\\UsersFindJob.java (at line 5)
[yjavac] import com.lowagie.text.Phrase;
[yjavac] ^^^^^^^^^^^
[yjavac] The import com.lowagie cannot be resolved
[yjavac] ----------
[yjavac] 3. ERROR in C:\\HYBRISCOMM6600P\\hybris\\bin\\custom\\training\\trainingcore\\src\\de\\hybris\\training\\core\\job\\UsersFindJob.java (at line 7)
[yjavac] import com.lowagie.text.pdf.PdfPTable;
[yjavac] ^^^^^^^^^^^
[yjavac] The import com.lowagie cannot be resolved
[yjavac] ----------
[yjavac] 4. ERROR in C:\\HYBRISCOMM6600P\\hybris\\bin\\custom\\training\\trainingcore\\src\\de\\hybris\\training\\core\\job\\UsersFindJob.java (at line 8)
[yjavac] import com.lowagie.text.pdf.PdfWriter;
[yjavac] ^^^^^^^^^^^
[yjavac] The import com.lowagie cannot be resolved
[yjavac] ----------
[yjavac] 5. ERROR in C:\\HYBRISCOMM6600P\\hybris\\bin\\custom\\training\\trainingcore\\src\\de\\hybris\\training\\core\\job\\UsersFindJob.java (at line 75)
[yjavac] Document documento = new Document();
[yjavac] ^^^^^^^^
[yjavac] Document cannot be resolved to a type
[yjavac] ----------
[yjavac] 6. ERROR in C:\\HYBRISCOMM6600P\\hybris\\bin\\custom\\training\\trainingcore\\src\\de\\hybris\\training\\core\\job\\UsersFindJob.java (at line 75)
[yjavac] Document documento = new Document();
[yjavac] ^^^^^^^^
[yjavac] Document cannot be resolved to a type
[yjavac] ----------
[yjavac] 7. ERROR in C:\\HYBRISCOMM6600P\\hybris\\bin\\custom\\training\\trainingcore\\src\\de\\hybris\\training\\core\\job\\UsersFindJob.java (at line 80)
[yjavac] PdfWriter.getInstance(documento, fop);
[yjavac] ^^^^^^^^^
[yjavac] PdfWriter cannot be resolved
[yjavac] ----------
[yjavac] 8. ERROR in C:\\HYBRISCOMM6600P\\hybris\\bin\\custom\\training\\trainingcore\\src\\de\\hybris\\training\\core\\job\\UsersFindJob.java (at line 88)
[yjavac] PdfPTable tabla = new PdfPTable(firstNames.size());
[yjavac] ^^^^^^^^^
[yjavac] PdfPTable cannot be resolved to a type
[yjavac] ----------
[yjavac] 9. ERROR in C:\\HYBRISCOMM6600P\\hybris\\bin\\custom\\training\\trainingcore\\src\\de\\hybris\\training\\core\\job\\UsersFindJob.java (at line 88)
[yjavac] PdfPTable tabla = new PdfPTable(firstNames.size());
[yjavac] ^^^^^^^^^
[yjavac] PdfPTable cannot be resolved to a type
[yjavac] ----------
[yjavac] 10. ERROR in C:\\HYBRISCOMM6600P\\hybris\\bin\\custom\\training\\trainingcore\\src\\de\\hybris\\training\\core\\job\\UsersFindJob.java (at line 91)
[yjavac] tabla.addCell(new Phrase(firstNames.get(i)));
[yjavac] ^^^^^^
[yjavac] Phrase cannot be resolved to a type
[yjavac] ----------
[yjavac] 10 problems (10 errors)

I also imported itextpdf-5.1.0.jar to <classpathentry kind="lib" path="lib/itextpdf-5.1.0.jar"/> but still same (after copying jar, did not do anything more except putting to .classpath)

Why do i get error?

None of solutions work on the net. none of them are for hybris.

what can i do? i could not find a way to java class . i need to export as pdf of given string array list.

The step you have followed is perfect to import external lib .

I think you need to focus on itextpdf doc for your version. With the latest version(itextpdf-5.1.0.jar) com.lowagie is not there. You should use com.itextpdf instead of com.lowagie

This answer will help you to resolve your issue.

You can refer this blog .

By default, hybris includes all libraries found in your extensions lib folder. In your IDE you need to reference the libs by yourself. Maybe you confused the lib folder? Check that you put the lib in

\\hybris\\bin\\custom\\training\\trainingcore\\lib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM