• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to add jar file to eclipse/ant

 
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm creating a new minimal project to use eclispe, ant, hibernate and xdoclet and junit and dbunit. I had an existing AppFuse project that was working so I copied the lib directory to my new project.

Now I wanted to add apache commons-lang v2.1 to the project. I tried making a new directory (commons-lang-2.1) in the lib directory and putting the jar file there. But when I went to project->properties->libraries->add Jar... the newly created directory would not show up! So I tried "Add class folder" it says "Exclusion filters have been added to nesting source folders". What does that mean? I don't know what "Add class folder" did but it did not help because I still cannot use "Add Jar" to add commons-lang v.2.1.

I ended up adding it as an external jar.

Incidently, how does one use the maven like feature where eclispse will automatically update the library?

Thanks,
Siegfried
 
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure whether any of this will help, but here are my thoughts...

First, a quick word on source directories: Source directories are those that Eclipse adds to the classpath in a project. Any Java files you want to edit must be in a source directory (or a subdirectory, i.e., if 'src' is a source directory, class com.foo.BarClass would be in directory src/com/foo). One property of source directories is that they cannot be nested. I.e., if 'src' is a source directory, then you can't set 'src/foo' to also be a source directory. This is intuitive - if they were nested, how could Eclipse tell whether a class Bar in directory 'foo' is supposed to be in package foo, or in the default package in source directory 'foo'? (I hope that wasn't too confusing :-\)

In this case, the way to add a JAR is as you did in the first attempt: just dump the JAR anywhere in your project, and add it using project->properties->java build path->libraries->add jar. (this is the location in Eclipse 3.1, I think it moved between 3.1 and 3.0).

If you can't find the JAR, chances are you need to refresh your workspace. Also, I just ran a quick test - JARs won't show up if you put then in a directory that you've set to be a source directory. Perhaps this is what you hit. If 'lib' contains only JARs (not .java files), then it shouldn't be a source directory.

I'm not familiar with Maven, so I can't help on the last point - but if you describe the functionality, perhaps I or someone else can.


-Tim
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,
When using Maven, you have a list of jars that your project uses. You can specify that you want the latest one. Maven automatically checks it's remote repository each time you run the build to see if a later version is out there. If so, it downloads it for you. Maven also downloads the file if it is missing (the first time you run the build.)

Siegfried,
I don't know of any functionality like that in Eclipse. You can connect to get the latest version of Eclipse plugins. But I don't know of anything that does so for libraries. Which isn't to say it doesn't exist of course.
 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ther ar some maven plugins..

I think one of them handles udpating the maven like libraries directly in Eclipse..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic