Copied project still uses wrong folder - java

How do I clone a workspace? I've tried copying its files from one folder to another but when using this Eclipse just opens the old folders. For easier understanding, I'll refer to the old folders as folder1 and the new one as folder2. I copy my workspace from folder1 to folder2. Using Eclipse, I select folder2 but all of the files are still grabbed from folder1.
If I try copying it, making a new folder and opening the project and refactoring it to the new folder, it just fails with the very undescriptive error that there was a problem moving the files. Without actually telling me what the problem is. The solution was to copy the workspace folder, and import the project using general>existing projects into workspace, but this failed too. I tried doing the same to an empty folder but this just linked the old folder to the new one instead of cloning them.
Tried looking in the Eclipse .metadata folder with no luck, even after changing the files I found that had the old directory it bizarrely doesn't open the new folders! I renamed the parts that point to /folder1 to point to /folder2, but somehow it still opens folder1 for everything when I select folder2. I've wasted nearly two hours stumped, digging into it with no dice and I'm turning to this community hoping to get some help.
Yes, I've Googled it, very few results actually helped, with the only one fitting my situation not working. I NEED to clone this, starting from scratch is simply not an option.

To clone a workspace:
Create a new workspace via File > Switch Workspace > Other... (this dialog offers also the option to copy your settings)
In the new workspace import the projects via File > Import...: General > Import Existing Projects into Workspace and make sure the checkbox Copy projects into workspace is checked
When the projects are located at different places or for transfer, you can also do File > Export...: General > Archive File first and then import the projects from that archive file.
Please note, the .metadata folder is not intended to be edited, moved or deleted.

Related

My projects are not appearing in eclipse

I face strange problem, Yesterday I was checking my projects and also I created a new project to the work-set.
Today when I opened eclipse and loaded my work-set I found that my projects are not loaded into eclipse. I checked the work-set folder I found that all my files exist in the work-set folder but those projects are not visible nor loaded into eclipse as if they are not exist.
I have also more than one workset,the one that does not appear in eclipse named workset00. workset00 folder exist one the hard drive but does not appear in eclipse. Unlike others worksets such as workset01 or workset02 they
I hope the I explained my problem clearly.thanks.
check out your workspace path is set properly to the workspace ur expecting to set or it different.. please check care fully directory by directory. if everything is proper still wont work, then do the following
copy all projects some other temporary folder and delete that directory.
create new workspace in eclpise.
just copy paste all ur project to the new workspace directory.
use import project from ecplise.
and your set
Try reimporting them or import them in a new workspace.

Eclipse - How to import a local source file into the same folder?

I wanted to import a file which was originally not imported into the source folder in Eclipse
What I did was:
I tried placing the file directory into a source file folder, which obviously did not work.
Then I right-clicked on folder->import->File System and tried to import that file, but eclipse then complains Source is in the hierarchy of destination.
What I did in the end was move the source file out of that folder, then import it back in from a different path, which I find really redundant.
What's the best way to include a file like that? Thanks in advance.
If you added (outside of Eclipse) a file to a source directory for your project, you should be able to get the file to show up in Eclipse by right-clicking your source folder in the Eclipse Package Explorer and selecting "Refresh" .
you can not import into the same folder bcz no OS allow to create multiple folder of the same name in same parent. instead, you put the folder being imported somewhere else, and while importing it to workspace, check the option to "copy into workspace"
As of October 2017, using Eclipse Oxygen 2017.1, I found that to accomplish what the OP wanted to do is not to what your natural instincts tell you to do.
In my case, I originally developed the code on Computer A in directory c:\projects\abc\ and copied the directory to computer B in directory c:\projects\abc\ outside of Eclipse.
Instead of
Import / General / File System /
which gives the error the OP mentioned, you instead need to:
Import / General / Projects from Folder or Archive /
When the dialog opens, point the "Import source:" to your already-present-where-it-needs-to-be directory (example: c:\projects\abc).
I left everything else to the defaults.
Click Finish.
When I return to Project Explorer, I did NOT need to Refresh the window. The project automatically showed up.
You've set up your Eclipse workspace and source code to be in the same folder i.e. the folder where your Eclipse .metadata resides is the same place as all your folders of code. Ideally, the folder for Eclipse's metadata should be somewhere else. (I did the same thing myself and then ran into all sorts of problems).
To expand on #user3785010 answer, I found that using Import > General > Existing Projects into Workspace worked for me with Eclipse Platform Version: 2021-09 (4.21).
When I tried Import > General > Projects from Folder or Archive, I pressed Finish and nothing happened.

Eclipse error with archived java projects "editor does not contain main type" [duplicate]

This question already has answers here:
Error: Selection does not contain a main type
(24 answers)
Closed 8 years ago.
I am receiving the errors: Editor does not contain main type, or, Selection does not contain main type when I import an archived Java project into Eclipse and try to run it. I have gotten this error on several different operating systems.
Archive Protocol
Export project
General->Archive File
All are selected: project folder, .classpath and .project
[x] save in zip format
[x] create directory structure for files
[x] compress contents of file
A Work Around That May Explain It... but how?!
I notice that when I import an archived project into an existing project (a blank Java project), The folder hierarchy is something like:
Project
src
bin
imported_project
bin
src
actual_code.java
Now, when I try to run actual_code.java, I get the above error. I discovered the following work around: if I drag actual_code.java and drop it into Project->src and then run it, it works.
This is a nice work around. However, I would prefer to be able to run the imported project without moving things around. Any suggestions on how to do this? It seems like it should be a trivial fix--it simply seems like the project isn't importing to where it ought to.
And yes...
I have tried every method I have come across to remedy this. That includes quite a few from this site and others: syntax, libraries, source path, restart eclipse, rearchive, different operating systems, different machines... etc.
The .java files are in the src folder before I archive them, and my build path seems correct.
You could import the archive as a Project instead of as files into a newly created blank project. Use Import > Existing Projects into Workspace. Then, use Select archive file.
You might want to put the src folder of your imported_project in classpath.
Right click on your project -> Properties -> Java Build Path -> Source -> Add Folder
I also faced the same error ajnd after reading above article i just drag/drop my class-file to src and new class-file generated in src is working fine .
I had the same problem after I New/Java Project then pulling src, docs, lib, examples, ... folders. I could not import it as an Eclipse project since the code is not an Eclipse project. The main is right there in the example code, but the IDE would find it.
The solution for me is deleting the project from the IDE, then recreating it with the Eclipse IDE. When recreating, the IDE cached all the sub-folders for me. Also, make sure you add the code onto the Java Build Path as Source using the 'Configure Build Path...' of the project.
Restarting IDE, closing then reopening the file didn't help me.

No Package Hierarchy Importing Project in Eclipse

I've been trying to import a project that works on a friend's computer, however no matter what I try, the package hierarchy is completely lost and the result is this
Has anyone seen this issue before? I've been struggling with it for a while. Occasionally creating a new project and copying in the src folder works, but I've been unsuccesfful in my recent attempts.
The presentation of packages is a user option. Click the little down-arrow at the top of the package panel, then select "Package Presentation" from flat to hierarchical.
Turns out we weren't including the .classpath file in the source control. Facepalm. Good answers, though.
It could also be that the folders are not listed in the project as Source Folders. Go to the project properties and check that the root folders (looks like "data" and "src" here) are listed as source folders in the Build Path.

How to create a project from existing source in Eclipse and then find it?

I have created several .java files. All of them are located in one directory. I used a text editor to write these files. Now I want to switch to Eclipse. How can I do it? I have tried many ways. None of them works.
ADDED:
I think the common way is to have source in the eclipse folder called "workspace". So, how do I get my files in these directory. Should I use eclipse to create a new project from existing source and Eclipse will put all file to the workspace? Or I should manually copy all my files to the workspace? Where should I put my class files than? Should I create a subdirectory? With which name?
ADDED 2:
When I try to create a project with name "game", the eclipse writes me that a project with such name already exist. But how can I open this project?
ADDED 3:
In my "workspace" I have created a subdirectory called "game". I copied all my .java file into this subdirectory. Then with Eclipse I created a new project with the name game. As a result, Eclipse created .classpath and .project files in the directory "game". It also created bin and src subdirectories. And now I think it is not the correct way to go. The source files are supposed to be in the "src" directory. Right? And at the moment all my .java files are in the "workspace\game".
ADDED 4:
I did it other way around. With Eclipse I have created a new project with the name "game". As the result, Eclipse created a folder called "game" into folder "workspace". In "game" the folder I found "src" folder. I copied all my .java files into this folder. But now in the "Package Explorer" I cannot open "src" folder. So, how can I access my source files from Eclipse? Why Eclipse does not want to open the "src" folder?
Easiest Method:
Put all source files into one directory named after your project. i.e. "ProjectName" You can keep this directory in your workspace or it can be somewhere else.
Start a new project in eclipse and name it using that same project name.
Uncheck the "use default location" box and find the directory where your project is unless your project is already in the workspace - then you must not uncheck the "use default location" box
Click 'next'.
Eclipse should be smart enough to figure out what's going on. After clicking next, it will show you all of the files it found in that directory. It will just automatically add those files to your project. VoilĂ !
Right-click in the package explorer and select New - Java Project
Create the new project Game
Open the new project in the package explorer - you should see only the source folder called src (there's nothing inside yet)
Open a file Explorer (e.g. Windows Explorer) and drag your sources
Drag them to Eclipse and drop them inside the new src folder - if asked select "Copy files"
Eclipse should put the files into the default package, if that's not correct you can edit the offending files (marked with a red cross) by opening them in Eclipse, selecting the package declaration (usually line 1), pressing Ctrl + 1 and selecting the appropriate option (e.g. "Move xy to package com.game"
This answer is going to be for the question
How to create a new eclipse project and add a folder or a new package into the project,
or how to build a new project for existing java files.
Create a new project from the menu
File->New-> Java Project
If you are going to add a new pakcage, then create the same package name here by
File->New-> Package
Click the name of the package in project navigator, and right click, and import...
Import->General->File system (choose your file or package)
this worked for me I hope it helps others.
Thank you.
The easiest method is really good but you don't get a standard Java project, i.e., the .java and .class files separated in different folders.
To get this very easily:
Create a folder called "ProjectName" on the workspace of Eclipse.
Copy or move your folder with the .java files to the "ProjectName" folder.
Create a new Java Project called "ProjectName" (with the Use default location marked).
Press <Enter> and that's it.
There are two things
1- If its already a Eclipse Project, then simply go to File->Import->General->Existing Project into Workplace
2- Otherwise define project type e.g. Java, Web etc
Create a new project of type you define into your workplace. Copy Paste source , lib and other necessary files. refresh, compile and run project in eclipse.
In the package explorer and the navigation screen you should now see the project you created. Note that eclipse will not copy your files, it will just allow you to use the existing source and edit it from eclipse.
There are several ways to add files to an existing Java project in Eclipse. So lets assume you have already created the Java project in Eclipse (e.g. using File -> New -> Project... - and select Java project).
To get Java files into the new project you can do any of the following. Note that there are other ways as well. The sequence is my preference.
Drag the files into the Navigator view directly from the native file manager. You must create any needed Java packages first. This method is best for a few files in an existing Java package.
Use File -> Import... - select File System. Here you can then select exactly which files to import into the new project and in which Java package to put them. This is extremely handy if you want to import many files or there are multiple Java packages.
Copy the fires directly to the folder/directory in the workspace and then use File -> Refresh to refresh the Eclipse view of the native system. Remember to select the new project before the refresh.
The last one is what you did - minus the refresh...
While creating a project from a full folder may or may not work within the workspace, there's a condition outside of the workspace that prevents starting a new project with a full folder.
This is relevant if you use numerous folder locations for sources, for example an htdocs or www folder for web projects, and a different location for desktop Java applications.
The condition mentioned occurs when Eclipse is told to create a new project, and given a full folder outside the workspace. Eclipse will say the folder isn't empty, and prevent creating a new project within the given folder. I haven't found a way around this, and any solution requires extra steps.
My favorite solution is as follows
Rename the full folder with an appended "Original" or "Backup.
Create the Eclipse project with the name of the full folder before the folder was renamed.
Copy all the relabeled full folders contents into the new project folder.
Eclipse should make a new project, and update that project with the new folder contents as it scans for changes. The existing sources are now part of the new project.
Although you had to perform three extra steps, you now have a backup with the original sources available, and are also able to use a copy of them in an existing project. If storage space is a concern, simply move/cut the source rather than fully copy the original folder contents.
If you creating a new project based on an existing Maven structure :
Create the project using a general project wizard and give the project the same name as just created.
If you try to create the project as a Maven project via m2e will receive an error that project/pom already exists.
Create a new project..
Right Click on your project..
Select Build path --> Configure Build Path
Under source tab choose link source, your .java files containing folder..
I am suggesting this since none of the methods that you tried have worked ---FYI
Follow this instructions from standard eclipse docs.
From the main menu bar, select command link File > Import.... The Import wizard opens.
Select General > Existing Project into Workspace and click Next.
Choose either Select root directory or Select archive file and click the associated Browse to locate the directory or file containing the projects.
Under Projects select the project or projects which you would like to import.
Click Finish to start the import.

Categories