Reputation: 2778
I am using afreechart and edu.emory.mathcs.jtransforms
and org.afree.chart
in numerous different activities I am writing for Android. I have a tremendous amount of trouble getting each new project configured so that I can
What I do now is make a copy of the .jar, doc src and .properties for each library I use. I copy those four things into the local lib folder for each project (one per activity) I am creating.
I must be missing something simple. It seems obvious that I should have these libraries, with their doc, src, and .properties, in one location, and that I should be able to reference that location in each project that uses those libraries. But I haven't figure out yet how to do that. Please tell me how.
If there is a way to define a set of jars and associated src & doc that will automatically and always be searched by any new eclipse project I do, that would be even better.
EDIT ADDED After answers about external Libs:
So indeed I did put jtransforms-2.4.jar in an external directory. In that same directory I put the src and doc for the package, and a file jtransforms-2.4.properties with a doc and src entry pointing at the local files with doc and src. I added them to my build path as external jar.
1) Eclipse IDE certainly found the classes in the .jar and flagged nothing as missing. 2) The doc and the src were shown as not attached. How do I put doc and src info along with the library so they automatically show up every place I link the jar as an external jar? 3) When I attempted to run the app, I got "NoClassDefFound errors for all the classes in the jar. That is, Eclipse IDE could find these classes in the external lib, but they did not make it in to the class path of the app.
SUMMARY: so the "external jar" technique has failed in two out of three important respects: 1) No src and doc show up as attached in eclipse IDE 2) do not provide updated class paths to the App.
FINALLY: when I copied the jar, .properties, doc and src in to the lib folder of my project, and removed the external jar reference, everything worked perfectly.
SO I reiterate my original question, the answers given (add to build path as external jar) did not solve anything.
Upvotes: 1
Views: 2011
Reputation: 3510
They keyword here is external. You can add library to your project without having them in your local lib folder. You just need to add them as "External Archives".
You can also add and alter them via your project's properties.
Although I dont think it's a good idea, to add some librarys to every project you create, there may be a script for that, but imo it's not a build-in function.
EDIT:
Well, it's not really built-in and it looks quit hackish to me, but this thread may be useful to you. It contains a way you can adress your problems via a properties file. You just need to create this file once and add it to your projects. So this is semi-automatic ;)
But I think this solution is better than adding it to every project since you shouldn't need all those libraries every single time...
EDIT 2: (after yours)
As to the 1st point:
There may be different reasons why the library doesnt work as an external library:
As I already mentioned, just adding it to the class path doesn't automatically provides linked srcs and docs. I recommend checking out the link above. With that technique you might achieve your goal semi-automatically.
But if you google about external jars and eclipse you encounter many people having the same issue as you have. So normally it should work out of the box. Would you mind updating your eclipse?
Another edit:
I totally forgot about the fact you are writing an Android app. Well, that's quite a special case. There many topics about this issue. Maybe you should also check out this one. With ADT17 placing you library in libs is triggering an automatic import. That's why it works this way for you.(When you place it in /libs)
Upvotes: 0
Reputation: 9294
You can use maven with android and if the jar is in maven central you just need to reference it.. If not, just put it in a local maven repo (I run one on my local machine).
Maven will manage dependencies such as this. Since eclipse has a maven plugin as well it will see your project references correctly as well. I recently made the switch and it was well worth it (but took several days to get it setup correctly).
Upvotes: 0