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

前端 未结 11 1819
难免孤独
难免孤独 2020-11-28 01:50

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

相关标签:
11条回答
  • 2020-11-28 01:57
    1. Right-click in the package explorer and select New - Java Project
    2. Create the new project Game
    3. Open the new project in the package explorer - you should see only the source folder called src (there's nothing inside yet)
    4. Open a file Explorer (e.g. Windows Explorer) and drag your sources
    5. Drag them to Eclipse and drop them inside the new src folder - if asked select "Copy files"
    6. 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"
    0 讨论(0)
  • 2020-11-28 01:58

    Easiest Method:

    1. 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.
    2. Start a new project in eclipse and name it using that same project name.
    3. 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
    4. 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à!

    0 讨论(0)
  • 2020-11-28 02:01

    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.

    0 讨论(0)
  • 2020-11-28 02:02

    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:

    1. Create a folder called "ProjectName" on the workspace of Eclipse.
    2. Copy or move your folder with the .java files to the "ProjectName" folder.
    3. Create a new Java Project called "ProjectName" (with the Use default location marked).
    4. Press <Enter> and that's it.
    0 讨论(0)
  • 2020-11-28 02:09

    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...

    0 讨论(0)
  • 2020-11-28 02:10

    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.

    0 讨论(0)
提交回复
热议问题