Creating Java Artifacts

The design pattern toolkit is able to generate Eclipse artifacts of any text type. When generating Java artifacts, however, there are some considerations to keep in mind.

Creating Java source files

When Java source files are created using the <start> template tag the resource name should be a file name relative to the project's source folder, not the project's root directory. For example, if a Java project has folder "/src" as the source folder, the resource attribute of the start tag for class com.yourcorp.YourClass.java would be "com/yourcorp/YourClass.java", even though the generated Java source would be placed in \src\com\yourcorp.

In this example, "com/yourcorp" would be understood to be a java package (because it contains a Java source file) and so any other type of text file placed in this folder would also be created in a subdirectory of the root java source folder.

Creating Java Projects

When you use the %lt;newProject%gt; template tag to create a Java project, you also need to create the project metadata files that tell Eclipse that the project has a Java nature. After creating the project, you should create two metadata files, .project and .classpath. You can create templates for these two files (e.g. classpath.pat and project.pat) and insert project metadata like the project name and any natures and builders you need for the project. Once you have created the project, the two metadata files and any other folders necessary (e.g. source and bin folders), use the %lt;checkpoint%gt; template tag to force the creation and recognition of that metadata before creating any addition Java source files. Java packages that are created before the checkpoint will not be created under the project's root source folder.

This same technique applies to creating other types of folders with other natures and metadata.


© Copyright IBM Corporation 2000, 2005. All Rights Reserved.