1

I'm using IntelliJ and I am trying to use the FileUtils.copyFile() method. When I use that method I get this error:

    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apach
e/commons/io/FileUtils

Here is the code that uses the copy file method:

import org.apache.commons.io.FileUtils;
...
    try {
         File destJAR = new File("c:/X-Dock/MP3Player.jar");
         File playerJAR = new File(MP3Player); //"MP3Player" is a string that is defined earlier.
         FileUtils.copyFile(playerJAR, destJAR);
    }catch (IOException e){
         e.printStackTrace();
    }

I imported the Apache Commons JAR "commons-io-2.4" into the IntelliJ project by going to

File -> Project Structure -> Libraries -> Add -> Java -> "commons-io-2.4.jar"

Any help would be greatly appreciated.

Sandeep Chatterjee
  • 3,220
  • 9
  • 31
  • 47
Arman
  • 655
  • 2
  • 7
  • 23
  • That error implies that `commons-io-2.4.jar` is not on your classpath at runtime. How are you running your program? – ruakh Jan 08 '15 at 02:19
  • @ruakh I build an executable jar file and run it. Or I just run it from intelliJ. I imported commons-io-2.4.jar just like many other external libraries – Arman Jan 08 '15 at 02:23
  • When you run your executable jar, how are you specifying the classpath? – ruakh Jan 08 '15 at 02:30
  • @ruakh I'm not entirely sure of what you mean by that. Can you explain – Arman Jan 08 '15 at 02:42
  • The build process (probably) does not embed `commons-io-2.4.jar` inside your own jar-file. Rather, it expects that `commons-io-2.4.jar` will be available at run-time; so your own jar-file relies on it, but doesn't supply it. The way you make it available at runtime is to include it in your classpath. For example, if you're running `java`, you would use the `-cp` argument to specify the classpath. – ruakh Jan 08 '15 at 04:32

1 Answers1

4

Follow these steps to resolve your problem. enter image description here

or you can edit configuration file

build.gradle

dependencies {
    compile files('libs/commons-io-2.4.jar')
}
Luc
  • 2,800
  • 2
  • 25
  • 46