1


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?

RE6
  • 2,684
  • 4
  • 31
  • 57

2 Answers2

1

You have to put the libraries in /libs folder of your project (if you are using Eclipse you choose "Add JARs.." not "Add external JARs..")

207
  • 3,784
  • 2
  • 25
  • 22
  • 1
    Have your refreshed/cleaned your project after adding libs folder? Did you also remove the "old" references to your external lib from the build path? – 207 Apr 15 '12 at 21:59
  • for me, doing several combination of menu/`Project`/`Clean...` and `right-click`->`refresh`, on the project, helped me. Before that, jars wouldn't even show up when trying adding them as (internal) `JAR`s at `Libraries` to the `Java Build Path` in project `Properties`. after refresh/clean they showed up there in the file tree. -- Although they are not in the `lib` folder for me, I've put them in `src`; so the comment was more useful to me than the answer. :) – n611x007 Sep 09 '13 at 13:01
1

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.

dtech
  • 13,741
  • 11
  • 48
  • 73
  • Your instructions are correct for R16 and earlier. For R17 and newer, just create a `libs/` directory if your project does not already have one, and copy the JAR into there -- no other project changes are required. – CommonsWare Apr 15 '12 at 21:30
  • @CommonsWare when I add the jars into libs/ it doesn't recognize it in the code, so I have to add it to build path right? – RE6 Apr 15 '12 at 21:35
  • @CommonsWare I cannot find a conversion from your R format to the more common "y.x" format. Which Eclipse version corresponds to R16/R17? – dtech Apr 15 '12 at 21:46
  • @dtech: 16 corresponds to 16. 17 corresponds to 17. Etc. That is how the ADT plugin is numbered, and the ADT is (mostly) upgraded in sync with the SDK tools – CommonsWare Apr 15 '12 at 21:48
  • 1
    @Ron: You are better served updating to the current SDK Tools (via the SDK Manager) and ADT plugin (via Help > Check for Updates in Eclipse), then just using the JAR in `libs/`. – CommonsWare Apr 15 '12 at 21:49
  • @CommonsWare Ah I totally overlooked that this was an Android related question :P – dtech Apr 15 '12 at 21:51