Java Annotation Facility - A Primer
JDK 5 Has Changed Source Code Generation in a Seminal Way
Mar. 9, 2005 12:00 AM
In this method of invocation we used the -nocompile to ensure that the source file specified isn't complied. The -classpath option specifies the classpath required by the processor. The -A option is ignored by the APT tool and is used by the annotation processor to get any specific processing-related information. In our case, we specified the location of the struts-config.xml in the file system.
The last step is to process the files with the annotation processor. Besides the command line, one could write an ANT Custom Task to generate the code. We strongly recommend that this be done. Since more and more projects are using ANT for automating the build process, it makes more sense to do an ANT build for automating code generation as well.
Writing an ANT task is easy and done by writing a custom task and extending the org.apache.tools.ant.Task class. Once that's done, the next step is to define the attributes and the corresponding setter methods for the attributes. The core processing logic is provided in the execute method called by the ANT framework. In our case, we delegate the bulk of the code generation work to the com.sun.tools.apt.main.Main class from the tools.jar. This is the actual byte code that's also used by the apt command line.
The following XML snippet from an ANT build shows how use the custom ANT task:
In this article we introduced the idea of defining annotation types, how to use defined types as annotation and how to go about generating code or other supporting files based on annotation. This new and powerful technology is transforming the way we code. As more and more tools and products start using this facility, developers will realize improved quality in their code and a concomitant increase in productivity.
Resources JavaCC: https://javacc.dev.java.net/
JSR 175: www.jcp.org/en/jsr/detail?id=175
Reader Feedback: Page 1 of 1
Really Excellent Information. But i have some doubts. initially i have some aversion towards annotations but after reading this article i develop some interest on it. later my R & D i want to create an annotation which is like @Singleton when ever i applied this annotation for a class then i want to make a class as singleton class. could you please help me out from this scenario.
in the same way @ThrowException(exceptionType="ArithmeticException.class")
many more ideas but i couldn't able to move in forward direction because there is no much information about annotations in Google also.
even no where i found the source code of this article. if you have any please send me complete source code with compilation and execution instructions. please please its really great help for me.my id is email@example.com
please send to this mail id .
Terry Corbet commented on 6 Aug 2006
This is a critique for the editor, not the author.
A primer that uses for an example something that requires experience with Struts is not what you should have provided. Ok, so the guy you got to do all the hard work happened to be interested in solving a Struts problem, but your job, as editor, should have been to carefully think through the issues of documenting this new Java facility and providing examples with as little dependence upon some specific toolkit-framework-environment as possible. With Mustang about to add to the value of annotation, I am sure there is much need for carefully-thought-out articles demonstrating valuable, incremental information. When K&R contrived 'Hello World', it was after thoughtful consideration about learning processes. Combined with the fact that the source code was not correctly provided, the overall impression is that you, as an editor, just thought you could get something for nothing and pass it along where enough Google hits would provide the mass of advertising that is blinking all around me as I enter this suggestion.
Vish commented on 21 Jul 2005
Sorry about that. Can you send me an email at firstname.lastname@example.org, and I will send you the src
Bob Shewan commented on 21 Jul 2005
As Neil noted there isn't any source code in the zip file. Would you be kind enough to send what you have.
vish krishnan commented on 13 Mar 2005
Neil, sorry about that. Send me an email and I will send you all the source that I have got. My email is unicode at yahoo dot com (OR) krviswanath at Deloitte dot com
Neil Hornbeck commented on 11 Mar 2005
The source zip file Viswanth1003.zip only contains compiled code.
Subscribe to the World's Most Powerful Newsletters
The dynamic nature of the cloud means that change is a constant when it comes to modern cloud-based ...
Mar. 23, 2018 09:30 AM EDT Reads: 3,480
DXWorldEXPO LLC announced today that Dez Blanchfield joined the faculty of CloudEXPO's "10-Year Anni...
Mar. 23, 2018 09:15 AM EDT Reads: 1,337
As DevOps methodologies expand their reach across the enterprise, organizations face the daunting ch...
Mar. 22, 2018 10:30 PM EDT Reads: 1,245
The standardization of container runtimes and images has sparked the creation of an almost overwhelm...
Mar. 22, 2018 10:15 PM EDT Reads: 1,791
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As au...
Mar. 22, 2018 07:00 PM EDT Reads: 1,474
DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held Novemb...
Mar. 22, 2018 01:45 PM EDT Reads: 4,418
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO an...
Mar. 22, 2018 01:30 PM EDT Reads: 1,945
DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, ...
Mar. 22, 2018 12:15 PM EDT Reads: 5,965
DXWorldEXPO | CloudEXPO are the world's most influential, independent events where Cloud Computing w...
Mar. 22, 2018 11:30 AM EDT Reads: 2,292
@DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held Novem...
Mar. 22, 2018 11:00 AM EDT Reads: 1,518
"We started a Master of Science in business analytics - that's the hot topic. We serve the business ...
Mar. 22, 2018 07:30 AM EDT Reads: 3,798
The best way to leverage your Cloud Expo presence as a sponsor and exhibitor is to plan your news an...
Mar. 21, 2018 02:30 PM EDT Reads: 1,997
As you move to the cloud, your network should be efficient, secure, and easy to manage. An enterpris...
Mar. 21, 2018 12:00 PM EDT Reads: 3,244
There is a huge demand for responsive, real-time mobile and web experiences, but current architectur...
Mar. 21, 2018 02:15 AM EDT Reads: 3,510
DXWorldEXPO LLC announced today that "Miami Blockchain Event by FinTechEXPO" has announced that its ...
Mar. 20, 2018 12:30 PM EDT Reads: 2,731
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will ...
Mar. 20, 2018 12:15 PM EDT Reads: 7,112
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to ...
Mar. 20, 2018 07:45 AM EDT Reads: 4,460
"NetApp is known as a data management leader but we do a lot more than just data management on-prem ...
Mar. 19, 2018 04:00 PM EDT Reads: 3,547
We call it DevOps but much of the time there’s a lot more discussion about the needs and concerns of...
Mar. 18, 2018 09:30 PM EDT Reads: 8,007
"Since we launched LinuxONE we learned a lot from our customers. More than anything what they respon...
Mar. 17, 2018 04:00 PM EDT Reads: 3,833