0

I am Create doc using,

package testreport;
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

public class creatrepo {

    public static void createDocFile(String fileName) {

        try {
            File file = new File(fileName);
            FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());

            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph tempParagraph = doc.createParagraph();
            XWPFRun tempRun = tempParagraph.createRun();

            tempRun.setText("Wel come");
            tempRun.setFontSize(12);
            doc.write(fos);
            fos.close();

            System.out.println(file.getAbsolutePath()+ " created successfully!");

        } catch (Exception e) {

        }

    }

    public static void main(String[] args) {

        createDocFile("/home/DocxFile.docx");


    }

}

I added jar file 'poi-3.14.jar' when run my code i getting error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openxmlformats/schemas/wordprocessingml/x2006/main/CTDocument1$Factory at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentCreate(XWPFDocument.java:282) at org.apache.poi.xwpf.usermodel.XWPFDocument.(XWPFDocument.java:136) at testreport.creatrepo.createDocFile(creatrepo.java:16) at testreport.creatrepo.main(creatrepo.java:36) Caused by: java.lang.ClassNotFoundException: org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1$Factory at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 4 more

help me

JohnPaul
  • 714
  • 5
  • 14
  • I am afraid, but it clearly says that NoClassDefFound, which means the package/jar which contains this class is not included in classpath during runtime. – piyushj Apr 27 '16 at 10:21
  • what i have to do for during runtime call the class – JohnPaul Apr 27 '16 at 10:22
  • may be this should help http://stackoverflow.com/questions/15106636/how-to-avoid-java-lang-noclassdeffounderror – piyushj Apr 27 '16 at 10:30

0 Answers0