Search code examples
javaeclipseeclipse-pluginapache-commons-io

Libraries in Eclipse plugin Project


I want to use the Apache commons.io for a plugin Project in Eclipse. I added the .jar to the buildpath:

(properties->java build path->Libraries)

But when I am trying to test my project, I get this error:

NoClassDefFoundError for org/apache/commons/io/FileUtils.

I think that Eclipse doesn't copy the library or that I miss to tell the project to copy that library.

How can I solve this problem? I am trying to write an export plugin where a complete folder is copied to another folder.


Solution

  • First look if there is already a eclipse plugin providing this library. For apache commons you will find one. Use the plugin editor and add depencies for the desired libraries, if they are common like apache commons ;)

    Other wise add directory call it "libs" and add your jars there. Then put them over the plugin editor to your classpath. To do this, use the tab "Runtime" and use the add button in the "classpath" section.

    this will end up in a build.properties like this

    source.. = src/
    output.. = bin/
    bin.includes = META-INF/,\
                   lib/commons-csv.jar,\
                   lib/commons-lang-2.6.jar,\
                   lib/commons-io-2.0.1.jar
    

    Libraries which are added this way, will be exported to your plugin to and they will remain in your classpath.

    The classpath of your project will be updated automaticly.

    Best practice for important libraries like a DB-Driver, put them in an extra plugin project, which is not extending the UI. Plugins like this will only have a build.properties. Then you can use this library plugin as dependency for other plugins.