views:

185

answers:

4
  1. I just installed Eclipse.

  2. The Eclipse created the "workspace" folder.

  3. In this folder I created a "game" sub-folder (for my class called "game"). I have already .java files for that project (I wrote them in a text editor before I started to use Eclipse).

  4. I put all my .java file into the "game" directory.

  5. In Eclipse I created a "New Java Project" from existing code.

What wanders me is that the Eclipse create a "src" sub-folder into my "game" folder. As far as I understand "src" stands for "source". But my source (.java files) is in the "game" (by the construction).

Am I doing something wrong?

ADDED:

I still cannot solve the problem. The whole day I am trying to start programming in Eclipse using existing code. It's incredibly complicated.

  1. Should I "Import Existing Project into Workspace" or should I "Create New Java Project from Existing code".

  2. Should I create "src" folder by hands and put in "workspace"?

  3. Should I create folders for packages or Eclipse will do it by itself?

  4. Should I copy my .java files to the package directory before or after I create a project in Eclipse?

A: 

The convention for Java is that your Java files are arranged by namespace under a 'src' directory. So if your application's namespace is com.example.myGame your Java files will be located thus src\com\example\myGame\MyClass.java.

Jim Blackler
Are you sure that "myGame" is in "src" (not "src" in "myGame")? I am asking because in my case "src" is in the "game" (not vice versa). And this order was created by Eclipse not by me.
Roman
A: 

Eclipse attempts to enforce a folder structure that is easy to maintain for all applications. You are not doing anything wrong. But you do have the option to select a different location for your source files but...everyone else expects your source code to be in src so why not.

On the New Project screen you can choose the location where you want your source files or configure the default location if you are not happy with src.

Vincent Ramdhanie
I happy with the "src" folder. I just cannot put my .java files in this folder. I mean, I just moved them to "src" but Eclipse still see them in "game" (in spite on the fact that I restarted the Eclipse).
Roman
+5  A: 

I would recommend keeping your sources separate from the eclipse workspace, and then use the function:

Import existing project into workspace.

alt text

That way you can keep your project under source control, while leaving Eclipse manage its workspace (located elsewhere) on its own.


If you have only sources (anywhere you want), but no Eclipse project, all you need to do create a New Java project, and select your external directory as root directory for your sources.

alt text

alt text

selecting "Create project from existing sources"

alt text

VonC
I need to select "root directory". I select folder where all my .java files are located and Eclipse writes me that "no projects are found to import".
Roman
@Roman: I have updated my answer to reflect your situation (no eclipse project, only sources)
VonC
Thanks for the extended answer!
Roman
A: 

src is where Java IDEs (at least Eclipse and NetBeans) put the source files, it is pretty much standard, and the hierarchy of the folder inside it has to match your Java packages names.

Bakkal
So in "src" I have different subdirectories corresponding to different packages? How can I get this structure in my case (I have already .java files for my package).
Roman
Jim Blackler's example is what you want, if you have a MyClass.java class that has to be in com.example.myGame package, then MyClass.java has to go in src/com/example/myGame/MyClass.java
Bakkal
You can change the source folder in eclipse or just add a source folder (src is the standard for input files and bin is the standard for temp files (.class), dist is common for files that will be distributed)
Romain Hippeau