"Source" Directories
In a Maven project, all the Java source for the application classes are stored as a package tree under the src/main/java subdirectory of the project. All test case source is stored under src/test/java. Resources (property files and other data files that must be copied to the same output location as the *.class files) are stored in the src/main/resources and src/test/resources directories. The Java source is compiled and the resources are copied to the target/classes subdirectory of the project.
An Eclipse Java project can have any number of source directories. The project Build Path (a project configuration dialog accessible from the menu system) has a Source tab that lists and managed the configured Source directories.
The Eclipse compiler automatically copies any file that does not end in *.java, and compiles the java source into an output directory. There is a global default output directory for the project, although individual source directories can have their own output directory.
So an Eclipse Maven project has to obey both conventions. The src/main/java and src/main/resources subdirectories will be configured as Build Path Source directories (and maybe also the test directories). The default output directory will be target/classes. This happens automatically when a Maven project is digested and turned into an Eclipse project by the Eclipse Maven plugin.
Java Source Files Appear Twice in the Project
When a directory is configured as a Java Source directory, then the Java source files under it appear twice in Project Explorer. Under the "src" subdirectory they appear as ordinary files, just as if they were text or html. This is generally not the useful version of the file and should be ignored. The better file listing occurs first in a special view of configured Source directories. Here information is displayed in Java language terms. So the Package name org.jasig.cas.adapters.jdbc is displayed in dotted notation as you would find in a Java package statement, instead of displaying each element of the path as a directory as in "org/jasig/cas/adapters/jdbc". It is in the Source directory display that Eclipse knows this is a Java program and has access to the specific Java language tools for editing and debugging.
In this example:
- the top line is the cas-server-support-jdbc Project
- it is followed by the src/main/java source directory
- that contains the org.jasig.cas.adaptors.jdbc Java package
- which in turn contains four Java source files
After two lines that show the dependencies and libraries, src appears a second time as a disk subdirectory of the project. Because this is the disk file view, there is no aggregation of package names using the Java x.y.z notation. Instead, each naming level is shown in its raw form as a directory on disk. Eventually the four Java source files are shown a second time, but now as ordinary files on disk rather than Java source files.
What is the difference between the two? When the Java files are first listed, they are preceded by the little triangle icon that means they can be opened further as a tree. If you open one, you find a class and if you open the class you find fields:
Whereas, down in the file display the same Java source file name has no tree icon. Viewed as a file instead of Java source, the source file is the bottom of the hierarchy and has no contents.
In this example, the four Java source files show up twice in the cas-server-support-jdbc project. However, as you either have already discovered or will shortly discover (depending on the order in which you read all the pages of this document) the actual project files are subdirectories of the cas3 (or cas-server) project. That is where they are physically located, while the cas-server-support-jdbc project is a view into that physical directory. So if you looked up in the first project (cas3) you will also find the same four files under cas3/cas-server-support-jdbc/src/main/java/...
While the source directories show up twice (once as java source files in packages and once as plain files on disk) the output directory of target/classes doesn't show up at all. From the Project Explorer you might imagine that there is not classes subdirectory of target, but if you open the workspace from outside Eclipse and navigate to the cas3/cas-server-support-jdbc/target directory you will find that classes is really there. This is an Eclipse trick to "hide" the output directory and all the *.class files it generates so the user isn't bothered by them. Eclipse wants the user to see things as source-only.