Question

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.

Was it helpful?

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.

OTHER TIPS

You are right, Eclipse does not copy the resources on projects build path. You need to them on your classpath. For that:

  • manually copy the jars to a location from where your application can consistently access them (brittle setup)

  • or use a build tool like ant, maven etc.(recommended)

Have you heard about Target Definition?
This is exactly what you need, and still you can use it with Maven (Tycho)...When developing plug-ins, you should always try to manage deps. via target definition, and never add jars in your classpath

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top