Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Eclipse: Referencing Jar files in Java Build Path

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

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.

Thanks!
- Himanshu
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Thanks!
- Himanshu
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic