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
Easiest Method:
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à!
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.
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.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...
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.