• 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

Importing a zipped package in Eclipse

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a package zipped using Winrar, and want to import it using Eclipse IDE. I did that by using the "Import" function when you right-click on your project's name. But, when I create a new class, and type, say:

import element.*;

I get an error.

What should I do?

Thanks.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What error do you get? The more details you tell us, the better we can help you. Is the error that it can't find the package named "element"?

If you want to use classes from one project in another project, you need to set the Java build path in the project where you want to use the other project: right-click the project, select Properties, select Java Build Path, Projects, and add the other project there.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be careful with using WinRAR - it uses (by default) a compression mechanism that is not compatible with the compression algorithm used for JAR files. Thus Java code, such as Eclipse, will not be able to access the contents.

Also, what "Import" function did you use? There are dozens of them. Was it "Archive File"?
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like you're confusing Eclipse code imports with java imports. There is a LOT of difference!

The eclipse import function copies files into you project. It does NOT simply make a references to the ZIP file, it actually unzips it into your project workspace. If you change or delete the original ZIP file, the project won't notice the difference, becausse it works only with the unzipped copies.

The Java import directive, on the other hand doesn't know or care about Eclipse. All it cares about is if the compiler can find the class(es) being imported in the compile classpath. Which is the same a the editor search path in the Eclipse Java editor/compiler framework. That classpath is defined in the project's Java build properties dialog.

So to find a class that's being imported via Eclipse, you have to import the class, either in object class form or as compilable source using the Eclipse import in order to copy it into the project workspace. Then, if it's java source, you have to either place it in a project source directory or designate the directory subtree that it was imported into as a project source directory. Finally, you have to make sure that the classfile itself is in the project's class path.

Finally, if you worked for me, you'd be required to make sure all that stuff could build with Ant or maven so that Eclipse wouldn't be the only way you could build a project. But that's because I have very strong opinions on staying IDE-independent.

In fact, I just had to disappoint a potential customer because I couldn't build an IDE-dependent project for him so that I could fix some critical bugs. The IDE was antique and to set up the old environment would have cost me more than he could afford to pay. If there'd been an old Ant script, there wouldn't have been a problem.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic