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?
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:
<Enter>
and that's it.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 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.
I am suggesting this since none of the methods that you tried have worked ---FYI
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.
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
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.
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.
this worked for me I hope it helps others. Thank you.
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.
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.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.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...
Follow this instructions from standard eclipse docs.
Source: Stackoverflow.com