Java, like many programming languages, provides support for organizing code into namespaces. In Java, namespaces are known as packages. In any project with more than two or three files and more than one or two developers, packages are a good way to make project structure understandable.
In addition, proper packaging ensures that namespace conflict are minimized. Two classes with the same name can be distinguished only if they are in different packages. Using no package, i.e. the default package, can be disruptive, as most Java tools expect classes to have fully-qualified names.
The floctrl
project uses the following package scheme as of 3/12/2012.
edu.cmu.cs.floctrl
. The use of the domain name structure follows standard Java conventions.pubsub
subpackage, giving full path of edu.cmu.cs.floctrl
.edu.cmu.cs.floctrl.conductor.gui
).edu.cmu.cs.floctrl.test
. If you have multiple test files, you can create subpackages of the test
package.Eclipse has good support for dealing with packages. You can create new packages in the same way you create new classes, using either File -> New -> Package
, the button in the toolbar next to the "New Java Class" button, or right-clicking in the Package Explorer panel and choosing New -> Package
.
Aside: If you do not have the Package Explorer open, go to Window -> Show View -> Package Explorer
Eclipse should be able to find the correct paths for any classes you want to use and automatically add import statements. Ctrl + Shift + O
is a handy shortcut for organizing and correcting import statements.
Eclipse can only manage import statements if it knows where all the necessary code is located. If your code depends on code that someone else wrote in a different project, you'll have to add that project as a dependency of your own project. Here's how:
Build Path -> Configure Build Path...
Projects
tabAdd...
buttonOK
Note that you have to have the projects open in your workspace to add them as dependencies. Use the File -> Import
menu to add the projects to your workspace.
Because of the way our git repository is setup, adding new subprojects is simple.
File -> New -> Java Project
(or use the toolbar icon)Use default location
.Browse
button and select the directory that was created when you checked out the repository. This directory should have all the other project folders inside.Because all the project folders are at the top-level of the git repository, there should be no path problems, because everyone with a copy of the repository should have the same structure.
If you do have path problems, make sure you haven't moved any projects out of the git repository.
The package structure was added by Billy Keyes on 3/12/2012. If you have any problems with the new structure, please email him.