NoClassDefFoundError for class never mentioned

Discussion in 'Plugin Development' started by ObsequiousNewt, Apr 22, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    ObsequiousNewt

    I'm writing a simple backup plugin (there are probably some out there, I know, but I'm writing this _myself_. The plugin saves the world files at a specified interval, then copies them over to a different folder. All of this was working fine. Then I added code to put the backups in a tar-archive, to save space. When I tried to run it, I got this error:
    Code:
    11:21:54 [INFO] Server permissions file permissions.yml is empty, ignoring it
    11:21:54 [INFO] Done (2.529s)! For help, type "help" or "?"
    11:22:04 [SEVERE] Exception in thread "Timer-0"
    11:22:04 [SEVERE] java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/ArchiveEntry
    11:22:04 [SEVERE]      at newts_world_backup.newts_world_backup$TimerTick.run(newts_world_backup.java:37)
    11:22:04 [SEVERE]      at java.util.TimerThread.mainLoop(Timer.java:534)
    11:22:04 [SEVERE]      at java.util.TimerThread.run(Timer.java:484)
    11:22:04 [SEVERE] Caused by: java.lang.ClassNotFoundException: org.apache.commons.compress.archivers.ArchiveEntry
    11:22:04 [SEVERE]      at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    11:22:04 [SEVERE]      at java.security.AccessController.doPrivileged(Native Method)
    11:22:04 [SEVERE]      at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    11:22:04 [SEVERE]      at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:41)
    11:22:04 [SEVERE]      at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)
    11:22:04 [SEVERE]      at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    11:22:04 [SEVERE]      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    11:22:04 [SEVERE]      ... 3 more
    
    The class "ArchiveEntry" is not mentioned in the specified line, nor anywhere else in the program. Here's the code for the newts_world_backup class:
    Code:java
    1.  
    2. package newts_world_backup;
    3.  
    4. import java.io.File;
    5. import java.util.Timer;
    6. import java.util.TimerTask;
    7. import java.util.logging.Logger;
    8.  
    9. import org.bukkit.World;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.util.FileUtil;
    12.  
    13. public class newts_world_backup extends JavaPlugin {
    14. public static Logger log;
    15. Timer timer = new Timer();
    16. File bak_folder = new File("NWB_BAK");
    17. public void onEnable(){
    18. log = this.getLogger();
    19. timer.schedule(new TimerTick(),10000,60000);
    20. if(!bak_folder.exists()){
    21. bak_folder.mkdir();
    22. log.info("Backup folder does not exist; creating it");
    23. }
    24. }
    25. public class TimerTick extends TimerTask {
    26. public void run(){
    27. String path = "NWB_BAK/"+System.currentTimeMillis()+System.getProperty("file.separator");
    28. new File(path).mkdir();
    29. for(World dim:getServer().getWorlds()){
    30. dim.save();
    31. File dest = new File(path+dim.getName());
    32. copy_server_files(dim.getWorldFolder(),dest);
    33. try {
    34. Thread.sleep(10);
    35. } catch (InterruptedException e) {
    36. log.severe("interrupted");
    37. }
    38. xzfm.compress(dest);
    39. }
    40. log.info("Backup completed");
    41. }
    42. }
    43. public void copy_server_files(File src, File dest){
    44. if(src.isDirectory()){
    45. if(!dest.exists()){dest.mkdir();}
    46. String files[] = src.list();
    47. for(String file:files){
    48. File srcFile = new File(src,file);
    49. File destFile = new File(dest,file);
    50. copy_server_files(srcFile,destFile);
    51. }
    52. }
    53. else{
    54. FileUtil.copy(src,dest);
    55. }
    56. }
    57. public static void log_error(Exception e){
    58. log.severe("Crashing!");
    59. log.severe(e.getMessage());
    60. log.severe(e.getStackTrace().toString());
    61. }
    62. }
    63.  

    And here's the code for the xzfm class (stands for XZ file manager, as I will eventually xz the tar archive):
    Code:java
    1.  
    2. package newts_world_backup;
    3.  
    4. import java.io.BufferedOutputStream;
    5. import java.io.File;
    6. import java.io.FileInputStream;
    7. import java.io.FileNotFoundException;
    8. import java.io.FileOutputStream;
    9.  
    10. import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
    11. import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
    12. import org.apache.commons.compress.utils.IOUtils;
    13.  
    14. public class xzfm {
    15.  
    16. public static void compress(File file){
    17. TarArchiveOutputStream out;
    18. try {
    19. out = new TarArchiveOutputStream(
    20. new FileOutputStream(file.getName()+".tar")));
    21. add_file(out,file);
    22. } catch (FileNotFoundException e) {
    23. newts_world_backup.log_error(e);
    24. }
    25. }
    26. public static void add_file(TarArchiveOutputStream out,File file){
    27. try{
    28. TarArchiveEntry tar_entry = new TarArchiveEntry(file);
    29. out.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
    30. out.putArchiveEntry(tar_entry);
    31. IOUtils.copy(new FileInputStream(file), out);
    32. out.closeArchiveEntry();
    33. if(file.listFiles() != null){
    34. for(File child:file.listFiles()){
    35. add_file(out,child);
    36. }
    37. }
    38. }
    39. catch(Exception e){
    40. newts_world_backup.log_error(e);
    41. }
    42. }
    43. }
    44.  

    I'm using Eclipse, with the Apache archive library. Bukkit library: bukkit-1.2.5-R1.2-20120415.233248-3.jar
     
  2. Offline

    nisovin

    The Apache archive library isn't part of Bukkit, so your plugin can't access it. You'll have to add it yourself.
     
  3. Offline

    ObsequiousNewt

    I did add it. Besides, I never mention ArchiveEntry.
     
  4. Offline

    nickrak

    TarArchiveEntry probably inherits ArchiveEntry.
     
  5. Offline

    ObsequiousNewt

    But the line last mentioned in the stacktrace contains neither ArchiveEntry nor TarArchiveEntry
     
  6. Offline

    ObsequiousNewt

    I have checked my libraries, and ArchiveEntry.class is right there. There is no fathomable reason why it shouldn't be running, unless the server jar needs the library as well.
     
  7. Offline

    nisovin

    Well, of course it does. Your plugin isn't a program that runs on its own, it runs within the context of the server.
     
    nickrak likes this.
  8. Offline

    ObsequiousNewt

    Regardless, I found a solution. Case closed.
     
Thread Status:
Not open for further replies.

Share This Page