1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
<refentry>
<refnamediv>
<refname>ajc</refname>
<refpurpose>compiler for the AspectJ language </refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>ajc</command>
<arg><replaceable>Options</replaceable></arg>
<group>
<arg><replaceable>file...</replaceable></arg>
<arg>@<replaceable>file...</replaceable></arg>
<arg>-argfile <replaceable>file...</replaceable></arg>
</group>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1 id="ajc" xreflabel="ajc">
<title>Description</title>
<para>The command <command>ajc</command> compiles AspectJ and Java
language source files into class files. Options and files may be
specified directly on the command line, or indirectly by naming a
file which contains them.</para>
<para> The arguments after the options specify the file(s) to compile.
Files may be listed directly on the command line, or listed in a file.
The <parameter>@<replaceable>file</replaceable></parameter> and
<parameter>-argfile <replaceable>file</replaceable></parameter> forms
are equivalent, and are interpreted as meaning all the files listed in
the specified file. Each line in these files should contain one option
or filename. Comments, as in Java, start with <literal>//</literal> and
extend to the end of the line.
</para>
<para>
<command>NB:</command> You must explicitly pass ajc all of the source files necessary
for the compilation. When you are compiling source files containing aspects
or pointcuts, be sure
to include the source files for any types affected by the aspects or
picked out by the pointcuts.
(If you wish to exclude types from the scope affected by the
aspect, change the corresponding pointcut or declaration.)
This is necessary because, unlike javac, ajc does not search the sourcepath for classes.
</para>
<refsect2>
<title>Options</title>
<variablelist>
<varlistentry>
<term>-verbose</term>
<listitem><para>
Output messages about what ajc is doing
</para></listitem>
</varlistentry>
<varlistentry>
<term>-version</term>
<listitem><para>
Print the version of ajc
</para></listitem>
</varlistentry>
<varlistentry>
<term>-nocomments</term>
<listitem><para>
Don't generate any comments into the woven code.
Only relevant with -preprocess mode.
</para></listitem>
</varlistentry>
<varlistentry>
<term>-emacssym</term>
<listitem><para>
Generate symbols used by AJDE for Emacs
</para></listitem>
</varlistentry>
<varlistentry>
<term>-usejavac</term>
<listitem><para>
Use javac to generate .class files
</para></listitem>
</varlistentry>
<varlistentry>
<term>-preprocess</term>
<listitem><para>
Don't try to generate any .class files.
Generate regular Java code into <replaceable>workingdir</replaceable>
</para></listitem>
</varlistentry>
<varlistentry>
<term>-workingdir <replaceable>Directory</replaceable></term>
<listitem><para>
Specify where to place intermediate .java files
<replaceable>Directory</replaceable> defaults to ./ajworkingdir.
Only relevant with -usejavac or -preprocess modes.
</para></listitem>
</varlistentry>
<varlistentry>
<term></term>
<listitem><para>
</para></listitem>
</varlistentry>
<varlistentry>
<term></term>
<listitem><para>
</para></listitem>
</varlistentry>
<varlistentry>
<term>-O</term>
<listitem><para>
Optimize; may hinder debugging or enlarge class files
</para></listitem>
</varlistentry>
<!-- We don't actually warn about deprecated methods ever
<varlistentry>
<term>-deprecation</term>
<listitem><para>
Output source locations where deprecated APIs are used
</para></listitem>
</varlistentry>
-->
<varlistentry>
<term>-d <replaceable>Directory</replaceable></term>
<listitem><para>
Specify where to place generated .class files
<replaceable>Directory</replaceable> defaults to the current working dir
</para></listitem>
</varlistentry>
<varlistentry>
<term></term>
<listitem><para>
</para></listitem>
</varlistentry>
<varlistentry>
<term>-classpath <replaceable>Path</replaceable></term>
<listitem><para>
Specify where to find user class files
</para></listitem>
</varlistentry>
<varlistentry>
<term>-bootclasspath <replaceable>Path</replaceable></term>
<listitem><para>
Override location of bootstrap class files
</para></listitem>
</varlistentry>
<varlistentry>
<term>-extdirs <replaceable>Path</replaceable></term>
<listitem><para>
Override location of installed extensions
</para></listitem>
</varlistentry>
<varlistentry>
<term>-argfile <replaceable>File</replaceable></term>
<listitem><para>
the file is a line-delimited list of arguments
these arguments are inserted into the argument list
</para></listitem>
</varlistentry>
<varlistentry>
<term>-encoding <replaceable>Encoding</replaceable></term>
<listitem><para>
Specify character encoding used by source files
</para></listitem>
</varlistentry>
<varlistentry>
<term>-source <replaceable>1.4</replaceable></term>
<listitem><para>
Specify support for assertions according to the 1.4 Java language.
This will treat <literal>assert</literal> as a keyword and will
implement assertions according to the 1.4 language spec.
</para></listitem>
</varlistentry>
<varlistentry>
<term>-lenient</term>
<listitem><para>
Be extra-lenient in interpreting the java specification
This allows some statements that some compilers consider errors.
</para></listitem>
</varlistentry>
<varlistentry>
<term>-strict</term>
<listitem><para>
Be extra-strict in interpreting the java specification
This signals errors for some statements that many compilers don't
catch, and generates code strictly according to the Java Language
Specification, even though such code may not run on 1.2 VMs.
</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
<refsect2> <title>File names</title>
<para>ajc accepts source files with either the <filename>.java</filename>
extension or the <filename>.aj</filename> extension. We normally use
<filename>.java</filename> for all of our files in an AspectJ system -- files
that contain aspects as well as files that contain classes. However, if
you have a need to mechanically distinguish files that use AspectJ's
additional functionality from those that are pure Java we recommend using
the <filename>.aj</filename> extension for those files.</para>
<para>We'd like to discourage other means of mechanical distinction such as
naming conventions or sub-packages in favor of the <filename>.aj</filename>
extension.</para>
<itemizedlist>
<listitem>Filename conventions are hard to enforce and lead to awkward names
for your aspects. Instead of <filename>TracingAspect.java</filename> we
recommend using <filename>Tracing.aj</filename> (or just
<filename>Tracing.java</filename>) instead.</listitem>
<listitem>Sub-packages move aspects out of their natural place in a system
and can create an artificial need for privileged aspects. Instead of
adding a sub-package like <filename>aspects</filename> we recommend using the
<filename>.aj</filename> extension and including these files in your existing
packages instead.</listitem>
</itemizedlist>
</refsect2>
<refsect2>
<title>Compatibility</title>
<para>
AspectJ is a compatible extension to the Java programming language. The
AspectJ compiler adheres to the <ulink
url="http://java.sun.com/docs/books/jls/index.html"> <citetitle
pubwork="book">The Java Language Specfication, Second
Edition</citetitle></ulink> and to the <ulink
url="http://java.sun.com/docs/books/vmspec/index.html"><citetitle
pubwork="book">The Java Virtual Machine Specification, Second
Edition</citetitle></ulink> and runs on any Java 2 compatible
platform. The code it generates runs on any Java 1.1 or later
compatible platform.</para>
</refsect2>
<refsect2>
<title>Examples</title>
<example id="simpleexample">
<title>A simple example</title>
<para>Compile two files:</para>
<programlisting>
ajc HelloWorld.java Trace.java
</programlisting>
</example>
<example id="exampleusingargfile">
<title>An example using -argfile/@</title>
<para>
To avoid specifying file names on the command line,
list source files in a line-delimited text argfile.
Source file paths may be absolute or relative to the argfile,
and may include other argfiles by @-reference.
The following file <literal>sources.lst</literal>
contains absolute and relative files and @-references:
<para><programlisting>
Gui.java
/home/user/src/Library.java
data/Repository.java
data/Access.java
@../../common/common.lst
@/home/user/src/lib.lst
view/body/ArrayView.java</programlisting></para>
Compile the files using either the -argfile or @ form:
<para><programlisting>
ajc -argfile sources.lst
ajc @sources.lst</programlisting></para>
</para>
<para>
Argfiles are also supported by jikes, javac, and ajdoc, so you
can use the files in hybrid builds. However, the support varies:
</para>
<simplelist>
<listitem>Only ajc accepts command-line options</listitem>
<listitem>Jikes and Javac do not accept internal @argfile references.
</listitem>
<listitem>Jikes and Javac only accept the @file form on the command line.</listitem>
</simplelist>
</example>
<!-- these examples suck
<example id="mixingoptionsandfiles">
<title>Mixing directly and indirectly specified options and
files</title>
<para>Invoke the AspectJ compiler with the options <literal>-threads
2</literal>, <literal>-deprecation</literal>,
<literal>-verbose</literal> and the options listed in the file
<filename>standard_ajc_options</filename> on the files listed in
<filename>prog_src_files</filename>. </para>
<programlisting>
ajc -threads 2 -deprecation @standard_ajc_options -argfile prog_src_files -verbose
</programlisting>
</example>
<example id="optionsnotinajc">
<title>Compiling with options not directly supported by
<command>ajc</command></title>
<para>Run the AspectJ compiler on the file
<filename>figures/FigureElement.java</filename> but do not generate
<filename>.class</filename> (bytecode) files. Keep the generated
Java source files and place them in the directory
<filename>tmp</filename>.</para>
<programlisting>
ajc -preprocess -workingdir tmp figures/FigureElement.java
</programlisting>
<para>You may then compile those files with:</para>
<programlisting>
cd tmp
javac -g figures/FigureElement.java
</programlisting>
</example>
<example id="usingjikes">
<title>Using <command>jikes</command></title>
<para>Invoke the AspectJ compiler on the file
<filename>figures/FigureElement.java</filename>, saving the
generated Java files in the directory
<filename>ajworkingdir</filename>. Then invoke the Jikes compiler
on the generated Java files.</para>
<programlisting>
JIKESPATH=$JAVA_HOME/jre/lib/rt.jar:$CLASSPATH
ajc -preprocess figures/FigureElement.java
cd ajworkingdir
jikes figures/FigureElement.java
</programlisting>
<para>Since <command>jikes</command> cannot infer the location of the
standard class files the way <command>javac</command> can, you must
tell it explicitly how to find the system and user class files it
needs. You may either use the <literal>-classpath</literal> option to
both <command>ajc</command> and to <command>jikes</command>, or you
may define the enviroment variables <envar>CLASSPATH</envar> and
<envar>JIKESPATH</envar> appropriately.</para>
</example>
-->
</refsect2>
<refsect2>
<title>The AspectJ compiler API</title>
<para>The AspectJ compiler is implemented completely in Java and can be
called as a Java class. The only interface that should be considered
public is the method <literal>org.aspectj.tools.ajc.Main.main(String[]
args)</literal>
where <literal>args</literal> are the standard <command>ajc</command>
command line arguments. This means that an alternative way to run the
compiler is </para>
<cmdsynopsis>
<command><literal>java org.aspectj.tools.ajc.Main</literal></command>
<arg><replaceable>option...</replaceable></arg>
<arg><replaceable>file...</replaceable></arg>
</cmdsynopsis>
<!-- <note> -->
<para>
To run in <literal>-usejavac</literal> mode,
you must include in your classpath the
<filename>tools.jar</filename> from your Java 2 developer's kit.
</para>
<!-- </note> -->
</refsect2>
<refsect2>
<title>Stack Traces and the SourceFile attribute</title>
<para>Unlike traditional java compilers, the AspectJ compiler may in
certain cases generate classfiles from multiple source files.
Unfortunately, the Java class file format does not support multiple
SourceFile attributes. So, in order to make sure all source file
information is available, the AspectJ compiler may in some cases
encode multiple filenames in the SourceFile attribute.
</para>
<para>Probably the only time you may see this format is when you view
stack traces, where you may encounter traces of the format
</para>
<programlisting>
java.lang.NullPointerException
at Main.new$constructor_call37(Main.java;SynchAspect.java[1k]:1030)
</programlisting>
<para>where instead of the usual
</para>
<programlisting>
File:LineNumber
</programlisting>
<para>format, you see
</para>
<programlisting>
File0;File1[Number1];File2[Number2] ... :LineNumber
</programlisting>
<para>In this case, LineNumber is the usual offset in lines plus the
"start line" of the actual source file. That means you use LineNumber
both to identify the source file and to find the line at issue.
The number in [brackets] after each file tells you the
virtual "start line" for that file (the first file has a start of 0).
</para>
<para> In our example from the null pointer exception trace,
the virtual start line is 1030. Since the file SynchAspect.java
"starts" at line 1000 [1k], the LineNumber points to line 30 of
SynchAspect.java.
</para>
<para> So, when faced with such stack traces, the way to find the actual
source location is to look through the list of "start line" numbers to
find the one just under the shown line number. That is the file where
the source location can actually be found. Then, subtract that "start
line" from the shown line number to find the actual line number within
that file.
</para>
<para>Of course, AspectJ tools will do this decoding for you, and in a
class file that comes from only a single source file, the AspectJ
compiler generates SourceFile attributes consistent with
traditional Java compilers.
</para>
</refsect2>
</refsect1>
</refentry>
<!-- Local variables: -->
<!-- fill-column: 79 -->
<!-- sgml-local-ecat-files: devguide.ced -->
<!-- sgml-parent-document:("devguide.sgml" "book" "refentry") -->
<!-- End: -->
|