|
Added
Link Here
|
| 1 |
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/nav.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menu.class.php"); $App = new App(); $Nav = new Nav(); $Menu = new Menu(); include($App->getProjectCommon()); # All on the same line to unclutter the user's desktop' |
| 2 |
# |
| 3 |
# Begin: page-specific settings. Change these. |
| 4 |
$pageTitle = "Introduction to Annotation Processing in Eclipse"; |
| 5 |
$pageKeywords = "JDT, Java, UI, Debug, APT, java, development, tools, java ide, Eclipse"; |
| 6 |
$pageAuthor = "JDT/APT team"; |
| 7 |
# End: page-specific settings |
| 8 |
# Paste your HTML content between the markers! |
| 9 |
ob_start(); |
| 10 |
?> |
| 11 |
|
| 12 |
<div id="midcolumn"> |
| 13 |
<h1> |
| 14 |
<?= $pageTitle ?> |
| 15 |
</h1> |
| 16 |
<div class="homeitem3col"> |
| 17 |
<h3>Disclaimer</h3> |
| 18 |
<p> |
| 19 |
This is a BETA release. All APIs contained herein are provisional, and subject to change with subsequent updates. |
| 20 |
</p> |
| 21 |
</div> |
| 22 |
<div class="homeitem3col"> |
| 23 |
<h3>Testing your APT installation</h3> |
| 24 |
<p> |
| 25 |
The APT feature is part of Eclipse 3.2, as of M5a and later. If you wish to use Eclipse 3.1, |
| 26 |
see the <a href="installOn3.1.html">3.1 installation instructions</a>. |
| 27 |
</p> |
| 28 |
<p>You can verify the installation on either version this way:</p> |
| 29 |
<ul> |
| 30 |
<li>Create a Java project which contains the file <a href="APTDemo.jar">APTDemo.jar</a> in its filesystem.</li> |
| 31 |
<li>Open the project properties dialog, and go to the Java Compiler / Annotation Processing panel.</li> |
| 32 |
<li>Check "Enable Project Specific Settings" and "Enable Annotation Processing".</li> |
| 33 |
<li>Now open the Java Compiler / Annotation Processing / Factory Path panel.</li> |
| 34 |
<li>Click on Add Jars... and add the APTDemo.jar.</li> |
| 35 |
<li>Create a new Class, and annotate the class in the source file with @DemoAnnotation(what = "spam").</li> |
| 36 |
</ul> |
| 37 |
<p>The "spam" value should be squiggled, with the message "I don't like spam".</p> |
| 38 |
<ul> |
| 39 |
<li>Annotate the same class with @TypeGeneratingAnnotation</li> |
| 40 |
<li>Build the project.</li> |
| 41 |
</ul> |
| 42 |
<p> |
| 43 |
A new source directory should appear in the project, named .apt_generated, that will contain a |
| 44 |
generated Java source file called GeneratedFileTest.java. <i>The generated source directory |
| 45 |
will not be visible by default in the Package Explorer, because it starts with a '.', but it |
| 46 |
will be visible in the Navigator.</i> |
| 47 |
</p> |
| 48 |
</div> |
| 49 |
<div class="homeitem3col"> |
| 50 |
<h3>Installing and Configuring Annotation Processors</h3> |
| 51 |
<p> |
| 52 |
An annotation processor can run in Eclipse from a .jar file contained in a project, a .jar file |
| 53 |
external to the workspace, or a plugin. Jars are added to a workspace or project though |
| 54 |
the Properties Dialog, Factory Path pane: |
| 55 |
</p> |
| 56 |
<img src="PropertiesDialog.gif"> |
| 57 |
<p> |
| 58 |
For an example of how to set up a plugin project to develop a processor, download |
| 59 |
<a href="APTDemo.jar">APTDemo.jar</a> and explode it into a workspace and import it as an |
| 60 |
existing project. Eclipse locates plugins along a factory path, which can be configured at the |
| 61 |
workspace or project level. Workspace configuration is picked up as the default for projects |
| 62 |
that have annotation processing enabled (see the Properties dialog shown above). If the |
| 63 |
factory path is configured for an individual project, that project will no longer see changes |
| 64 |
to the workspace configuration; you will have to update it manually. |
| 65 |
</p> |
| 66 |
<p> |
| 67 |
A plugin that contains a factory must extend the annotationProcessorFactory extension |
| 68 |
point. Here is the example from the plugin in APTDemo.jar. Each Factory class contained in the |
| 69 |
plugin must be named in the class=attribute. |
| 70 |
</p> |
| 71 |
<pre> |
| 72 |
<extension |
| 73 |
point="org.eclipse.jdt.apt.core.annotationProcessorFactory"> |
| 74 |
<factories enableDefault="true"> |
| 75 |
<factory |
| 76 |
class="demo.TypeGeneratingAnnotationProcessorFactory"> |
| 77 |
</factory> |
| 78 |
<factory |
| 79 |
class="demo.DemoAnnotationProcessorFactory"> |
| 80 |
</factory> |
| 81 |
</factories> |
| 82 |
</extension> |
| 83 |
</pre> |
| 84 |
<p> |
| 85 |
More details about this will follow when we deliver an SDK version of the feature. |
| 86 |
</p> |
| 87 |
</div> |
| 88 |
<div class="homeitem3col"> |
| 89 |
<h3>Debugging Annotation Processors in Eclipse</h3> |
| 90 |
<p> |
| 91 |
To debug an annotation processor it must be |
| 92 |
run from a plugin. You develop your code in the plugin, and then debug it by annotating |
| 93 |
source code in a spawned instance of Eclipse. The debugging instance needs the annotation |
| 94 |
declaration, the factory, and the processor. The spawned instance only needs access to the |
| 95 |
declaration. |
| 96 |
</p> |
| 97 |
</div> |
| 98 |
<div class="homeitem3col"> |
| 99 |
<h3>Problems and Bugs</h3> |
| 100 |
<div> |
| 101 |
<p>Symptom: nothing happens, no errors in log file.</p> |
| 102 |
<ul> |
| 103 |
<li>Make sure that annotation processing is enabled in the Project Properties.</li> |
| 104 |
</ul> |
| 105 |
<p>Symptom: annotations not getting processed, log file contains "Bundle not resolved" |
| 106 |
warnings, ClassNotFound errors or "No Classloader found" errors.</p> |
| 107 |
<ul> |
| 108 |
<li>Make sure that you are using a 1.5 JVM to run Eclipse. Although most of Eclipse |
| 109 |
can run on a 1.4 JVM, the APT plugins require a 1.5 JVM.</li> |
| 110 |
</ul> |
| 111 |
<p>Please post questions to the JDT newsgroup (eclipse.tools.jdt). Post bugs related to |
| 112 |
this feature in Bugzilla, under Product JDT, Component APT. |
| 113 |
</p> |
| 114 |
</div> |
| 115 |
</div> |
| 116 |
<div class="homeitem3col"> |
| 117 |
<h3>Feature Enable/Disable in Eclipse 3.1.2</h3> |
| 118 |
<p> |
| 119 |
If you installed APT as an update to |
| 120 |
Eclipse 3.1.2 and you have a problem with the compiler, you can disable the feature |
| 121 |
through the Product Configuration dialog (Menu item Help / Software Updates / |
| 122 |
Manage Configuration). |
| 123 |
</p> |
| 124 |
<img src="ProductConfigDialog.jpg"> |
| 125 |
<p> |
| 126 |
Select the JdtAptFeature from your Eclipse installation and click <b>Disable</b>. Your |
| 127 |
Eclipse will now use the unchanged, original version of the compiler. To re-enable the |
| 128 |
feature you need to click on the Show Disabled Features on the toolbar of this dialog. |
| 129 |
</p> |
| 130 |
</div> |
| 131 |
</div> |
| 132 |
<?php |
| 133 |
$html = ob_get_contents(); |
| 134 |
ob_end_clean(); |
| 135 |
|
| 136 |
# Generate the web page |
| 137 |
$App->generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html); |
| 138 |
?> |