4 Replies - 602 Views - Last Post: 09 July 2011 - 10:09 PM Rate Topic: -----

#1 maffelu  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 43
  • View blog
  • Posts: 190
  • Joined: 21-August 08

How to structure a project in Eclipse

Posted 09 July 2011 - 01:28 PM

I'm a .NET developer who's doing some serious java (oh yes!) and I'm having problems structuring my projects in eclipse. In a .NET I would structure a project like this (roughly, and as an example :whistling: ):

MyProject.Core
Exceptions
InvalidHairColorException.cs
NullNameException.cs
People
Person.cs
Employee.cs
Boss.cs


MyProject.Data
Repositories
EmployeeRepository.cs
WorkplaceRepository.cs


etc etc etc

I would have a layered structure where the Business layer holds a reference to the Core and Data layer and the Gui would have a reference to the Business layer.

However, and here are the two questions, in eclipse I don't seem to be able to get this folder structure that I have Visual Studio (I know it's an IDE feature as it's all a definition of namespaces, but it helps with bigger projects), is it even possible in Eclipse. The seconds question is a lot easier. How the #"!% do you actually reference projects in java? Do I put the Core, Business, Data and Gui in the same workspace or separate workspaces?

Please, I hate working in an unstructured manner, it's painful :helpsmilie:

Is This A Good Question/Topic? 0
  • +

Replies To: How to structure a project in Eclipse

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: How to structure a project in Eclipse

Posted 09 July 2011 - 02:33 PM

Java is different to .net, and eclipse is quite different from visual studio. In java, we dont really do namespaces. But you can achieve structures like you want to achieve. Generally, you go with a design pattern, such as MVC, and you structure your project according. So, in eclipse, I am going to create a project call MyProject. MyProject now becomes my root folder

MyProject

Now I need to know what I want to put in this project, and as you know, this all depends on what your trying to achieve. For the fun of this, and because I am working on it at the moment, lets look at a component within a virtual world. I know that this virtual world component (lets say a piano model for instance, which is able to play music based on keyboard input) is going to have four major parts to it
client - for client side coding
cell rendering - for rendering the model
common - classes which are accessed by client and server
server - server side code.

So now, my project is starting to look like this
MyProject
client
cellRender
common
server
(Sorry, wont indent the four folders)
Thats before even any classes are added. So within these folders, the appropiate classes can be added. Now your problably thinking what if some of these classes use assets, how can I store these? Well simple answer is its up to the developer. Lets look at the CellRender folder. In here, I know my model will sit, along with any materials for it. So What I would do is straight away make a new folder inside it called Assets. Inside this, I would make a folder called models and one called material.

It really is up to the developer to think of the best way to structure their project. In the above sample, if I ever need my server talking to my client, I would do this within a class stored in the common folder. Its not really namespaces that allow me access to these classes, but instances and methods.

If you have any more questions, feel free to ask.

This post has been edited by nick2price: 09 July 2011 - 02:34 PM

Was This Post Helpful? 1
  • +
  • -

#3 maffelu  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 43
  • View blog
  • Posts: 190
  • Joined: 21-August 08

Re: How to structure a project in Eclipse

Posted 09 July 2011 - 02:48 PM

Well, I'm feeling pretty free :)

First of all, thanks for replying.

My problem is, to be honest, mostly visual actually. The problem is not that I can't create folders, the problem is that I can't create folders inside packages. Whenever I create a class I need to have it inside a package, say com.myproject.data.

In com.myproject.data it would feel natural to put my DbManager.java file. I then create com.myproject.data.repositories (as they are a part of my data package) and before I start adding my 39 different repositories I realize I need to structure them even further, so I make

com.myproject.data
DbManager.java

com.myproject.data.repositories
BaseRepository.java

com.myproject.data.repositories.people
PeopleRepository.java
FamilyRepository.java
EmployessRepository.java

com.myproject.data.repositories.users
UserRepository.java


Do you see my problem? I will end up with a 100 packages in one folder. I would like to have a foldered structure so that I don't have to scroll for eternity whenever I look fore files. The structure above would, in folders, be:

com.myproject.data
DbManager.java
com.myproject.data.repositories
BaseRepository.java

com.myproject.data.repositories.people
PeopleRepository.java
FamilyRepository.java
EmployessRepository.java

com.myproject.data.repositories.users
UserRepository.java

Was This Post Helpful? 0
  • +
  • -

#4 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: How to structure a project in Eclipse

Posted 09 July 2011 - 03:15 PM

Ok i see. What you want to do can be easily achieved, but I will let someone with more knowledge on eclipse than me advise you (I tend to use Netbeans). Then what you know as namespaces, I think would be the equavilant to our imports. So when I need to use something from a class which is located somewhere else, I can do at the top of my class
import org.jdesktop.wonderland.client.cell.registry.annotation.CellFactory;
import org.jdesktop.wonderland.client.cell.registry.spi.CellFactorySPI;
import org.jdesktop.wonderland.common.cell.state.CellServerState;
import org.jdesktop.wonderland.modules.piano.common.PianoCellServerState;



I am trying to read up on namespaces, but not truely understanding what they are used for. So someone should be able to let you know if they are more like imports as above, or instances like below
MyClass mClass = new MyClass();

Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8347
  • View blog
  • Posts: 31,912
  • Joined: 06-March 08

Re: How to structure a project in Eclipse

Posted 09 July 2011 - 10:09 PM

View Postmaffelu, on 09 July 2011 - 05:48 PM, said:

My problem is, to be honest, mostly visual actually. The problem is not that I can't create folders, the problem is that I can't create folders inside packages.

Yes but they are packages :)

A package name in Java is a directory structure

so

com.myproject.gui is: /com/myproject/gui and
com.myproject.gui.cell is: /com/myproject/gui/cell

the same as the API is structure

The class ArrayList is in /java/util/ArrayList.class
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1