This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSF and the fly likes Why can't I import most projects I download into eclipse? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Why can Watch "Why can New topic
Author

Why can't I import most projects I download into eclipse?

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

When I try to download source code for an example and then import it to eclpise, most of the time it will not work for me. I download the project as a zip file. Then in eclipse Ill go to file->import->existing project into workspace

I then select "Select Archive File:" and browse to the zip file I just downloaded.

Sometimes this will work for me, but most of the time the "Projects" space will have nothing in it and the Next button will still be greyed out. But then other times the projects space will populate, the Next button is activated and I can import with no issues.

I've noticed the projects that will not import always have a very different file structure than the default structure in eclipse. And the files I can import have the exact same file structure. I'm sure this is part of the issue, but I have no idea what to do to get around this.

Any suggestions?


True wisdom is in knowing you know nothing - Socrates
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

I'd be curious as to how the projects you're getting were exported? Do they just contain source code, or do they also contain the metadata directory and stuff that Eclipse uses to describe a project?

If it's just Java, you can just create a project yourself, and them do a normal import of the code.

-Cameron McKenzie
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I am trying to import JSF projects I shouldve said. These are not projects I have exported, they are samples online from other people I am trying to download.

Here is the file structure Im used to:




Whenever I try to import a jsf project from someone online that follows this file structure I can do so just fine. However when i get a project that differs in any way (usually there will be something like a class folder to hold all the classes, etc) I get the problem as I described above.
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

sorry, I read too hastily and did not comprehend your response.
and looking into it, no the metadata is not there.

a good example is at www.corejsf.com

That is the accompanyng site for a textbook I bought. It has a lot of example code. Each chapter has examples, each with a src and a web folder, containing the usual stuff. I misunderstood how eclipse imported projects. I assumed as long as the src and web folders were present eclipse would construct the project. Just by your response though I realize where I was wrong about this. My question is answered now, thank you
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16158
    
  21

This is tricky. You can't literally import a project into Eclipse - just its files. To establish a project as an Eclipse project, you have to build an actual Eclipse "project".

In other words, use the File/New menu to create a blank project, including the ".project" file. CVS checkouts also do that as an option when importing from CVS, but they're still creating a project and then filling it in, not simply downloading it.

Importing files into a project is REALLY tricky. The Eclipse import/export functions are not very good at letting you root your project files in the right place.

As an example, suppose I exported my project "XYZ", and its original root was the "XYZ" directory. When I export it, the XYZ directory and all its subdirectories (subject to my selections) will be exported. Now let's assume I wanted to clone the project and name it "ABC". If I import the zipfile, I have to first designate the target project. So I build a project named "ABC" and import it.

At this point, one of 2 things will bite me.

1. The import won't let me root things properly, resulting in an ABC/XYZ directory structure.

2. The import will want to import into XYZ, not ABC

In practice, I usually address this by importing XYZ under ABC, exiting Eclipse, then hoisting all the files and directories in ABC/XYZ up a level (that is, from ABC/XYZ to ABC), then removing the now-empty ABC/XYZ directory. Then I restart Eclipse and refresh the project, if needed.

It's quite safe to overlay the .project and .classpath files that were created when you defined the ABC project with .project and .classpath that was included in the XYZ zip. But it is safer to do this while Eclipse isn't running, which is why I shut down Eclipse while moving the files.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why can't I import most projects I download into eclipse?