File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes IDEs, Version Control and other tools and the fly likes Eclipse: Referencing Jar files in Java Build Path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Eclipse: Referencing Jar files in Java Build Path" Watch "Eclipse: Referencing Jar files in Java Build Path" New topic

Eclipse: Referencing Jar files in Java Build Path

Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134

I am having problems with Eclipse projects. I make a new Java project and in the 'Java Build Path --> Libraries' specify a jar file (Any jar file, for example - axis.jar). I click ok and then import certain code that references the package org.apache.axis. Eclipse marks these references as Compilation Errors. Per my understanding, I should not get compilation errors since the jar file (axis.jar) is present in my 'Libraries' (in effect being present on my Classpath). Is my understanding incorrect? Am I missing something here?

After struggling for a long time with this, I experimented some more and did a 'File --> Import --> archive file'. I imported the axis.jar this way - and it exploded the axis.jar file into individual packages into my project's workspace. This resolves my compilation problem. But, I still don't like the clutter of the individual packages in my project's workspace.

Any help would be appreciated.

- Himanshu

Himanshu Jhamb<br />SCJP2 v1.2 (April 2002)<br />SCJP2 v1.4 (May 2002)
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
That sounds right. Just to make sure.

You have a project.
You right click the project and select properties.
Select Java Build Path.
Select Libraries.
Click the Add Jar button.
Select a jar file.
Click ok and ok again.

The jar file now shows up in the in the top level of the package explorer with a little jar looking icon next to it. If you've done all that and still are getting compile errors I would first do a 'project > clean' to get a clean compile, and then look at the fully qualified name in the import where it shows as a compile error and make sure that class does indeed exist in the jar you imported.
Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
Hi Steve,
Thanks for your reply.

Although your comments were extremely helpful in improving my understanding of Eclipse, the problem was somewhere else. After I had referenced my libraries - I guess Eclipse automatically references them in the classpath for that project. When I did the import of the file system, my file system contained a classpath that was overwriting the original classpath of the project thereby deleting the references created, earlier.

The problem got resolved when I explicitly asked Eclipse not to overwrite my existing classpath.

I thought I will just write the resolution in case this is helpful to anyone in the future.

- Himanshu
I agree. Here's the link:
subject: Eclipse: Referencing Jar files in Java Build Path
It's not a secret anymore!