Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

Version 1 Next »

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.

Directories Appear in Two Places

When you designate a particular directory to be an Eclipse Build Path Source directory, it is in the first group of directories listed for that project in the Project Explorer view.

In this example, the source directory src/main/java appears as the first thing in the project, and if you expand it you find the org.jasig.cas.adaptors.jdbc package that in turn contains four classes in source. However, a little farther down in the same project you find the src subdirectory viewed as a regular directory on disk and if you expand that directory tree you find the same four java sources viewed this time as files on disk.

The first entry is triggered by the Build Path Source entry that tells Eclipse to look starting at src/main/java for files to compile. However, all directories and files in the project, whether they have been designated as Build Path Source or not, also appear later in the project as just files on disk that are inside the project directory. Unfortunately, Eclipse uses the term "resource" to refer to non-source files, which can confuse you about real resources in the src/main/resources directory (had one existed). Eclipse should have used some other term to refer to the directory trees at the end of every project which show all the directories under the project directory.

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.

  • No labels