aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes How to add jar file to eclipse/ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "How to add jar file to eclipse/ant" Watch "How to add jar file to eclipse/ant" New topic
Author

How to add jar file to eclipse/ant

Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 388
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
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
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
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30919
    
158

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Fred Grott
Ranch Hand

Joined: Oct 05, 2002
Posts: 346
Ther ar some maven plugins..

I think one of them handles udpating the maven like libraries directly in Eclipse..


MobileBytes blog - Sharing Technology - My Programming Knols
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add jar file to eclipse/ant