Search code examples
javaandroideclipsejarbuildpath

Eclipse (probably) doesn't compile external jars



Suddenly, all my code depending on external jars doesn't work.
For example:

Jsoup.parse(str)

gives:

could not resolve type: org.jsoup.Jsoup 

And i'm 100% sure that it is in the build path.
Maybe it happenned because I updated the ADT plugin and the platform tools to the latest version, but it doesn't make sense...
But it started occuring since I updated those.
So apparently eclipse doesn't compile those jars. (In code, it DOES resolve the jars types)...
Do you maybe know what is the problem?


Solution

  • This has nothing to do with compilation: jar's are already compiled.

    You only need to add the jar to your project classpath so Eclipse will know to run java with the .jar. You can do this with "Context/Right click menu->Properties > Java Build Path > Libraries" (source). For portability I recommend placing the .jar in a subdirectory of your project. A "lib" folder in your project root (where "bin" and "src" are too) is commonly used.

    Also note that to run your program you will need to add the dependency .jar to your java command, but with a little searching you can find out how to include the dependency .jar in your own combined .jar.