Skip to content

Instantly share code, notes, and snippets.

@paul-xor
Created April 5, 2016 17:24
Show Gist options
  • Save paul-xor/261d9357b88e84e3e781a1793055b930 to your computer and use it in GitHub Desktop.
Save paul-xor/261d9357b88e84e3e781a1793055b930 to your computer and use it in GitHub Desktop.
Error. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
/*
* 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 ua.cons;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
*
* @author smolov
*/
public class Jcons {
private final String temp;
private final String path;
public Jcons(String temp, String path) {
this.temp = temp;
this.path = path;
}
public void Iocon(){
File directory = new File(path);
File[] items;
FilenameFilter filter = (File dir, String name) -> {
if(name.lastIndexOf('.')>0)
{
// get last index for '.' char
int lastIndex = name.lastIndexOf('.');
// get extension
String str = name.substring(lastIndex);
// match path name extension
if(str.equals(".xlsm"))
{
return true;
}
}
return false;
};
items = directory.listFiles(filter);
if(items==null){
System.out.println("ERRROR: No files in the folder");
}
for(File item:items){
if(item.isFile()){
//System.out.println(item.getName() + "; " + item.getPath());
try (Workbook wbSrc = new XSSFWorkbook(OPCPackage.open(item.getPath()))) {
// todo ...
wbSrc.createSheet("New Sheet");
FileOutputStream fos = new FileOutputStream("x:\\tmp\\new_edited.xlsm");
wbSrc.write(fos);
fos.close();
} catch (IOException | InvalidFormatException ex) {
//Logger.getLogger(Jcons.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
@paul-xor
Copy link
Author

paul-xor commented Apr 5, 2016

`Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject

at ua.cons.Jcons.Iocon(Jcons.java:64)
at ua.cons.Main.main(Main.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
    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)
    ... 2 more

C:\Users\smolov\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)`

@paul-xor
Copy link
Author

paul-xor commented Apr 5, 2016

RESOLVED:

  • xlmbeans-2.6.0.jar to Libraries and everything running smoothly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment