我是使用
创建文档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");
}
}
我在运行我的代码时添加了jar文件'poi-3.14.jar'
我收到错误:
线程中的异常" main" java.lang.NoClassDefFoundError:org / openxmlformats / schemas / wordprocessingml / x2006 / main / CTDocument1 $ Factory 在org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentCreate(XWPFDocument.java:282) 在org.apache.poi.xwpf.usermodel.XWPFDocument。(XWPFDocument.java:136) at testreport.creatrepo.createDocFile(creatrepo.java:16) 在testreport.creatrepo.main(creatrepo.java:36) 引起: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个
帮帮我