Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

AspectJ and Ant

DZone's Guide to

AspectJ and Ant

· Java Zone
Free Resource

Managing a MongoDB deployment? Take a load off and live migrate to MongoDB Atlas, the official automated service, with little to no downtime.

I've just started working with AspectJ and despite its non-intuitive syntax, I'm pretty sold on its effectiveness at reducing development time and pre complexity by factoring out crosscutting concerns such as logging and security. However, the Internet is a little lacking in guides and how to build it, so here's my how to.

1) Download AspectJ tools jar and save this into your ~/.ant/lib directory.

2) Add the XML namespace to the project element:

<project xmlns:aspectj="antlib:org.aspectj" ...
Create a new compile target in your build.xml (you can see that I use Ivy for dependency management):
	<target name="compile.aspectj" depends="resolve">
		<mkdir dir="${build}" />
		<aspectj:iajc source="1.6" destDir="${build}">
			<sourceroots>
				<pathelement location="${src}" />
			</sourceroots>
			<classpath>
				<fileset dir="${lib}">
					<include name="**/*.jar" />
				</fileset>
			</classpath>
		</aspectj:iajc>
	</target>

Note: you may need to tell AspectJ to use target Java 6.

3) Factor out the javac element into it's own "compile.javac" task, this wil allow you to revert to javac easily:

	<target name="compile.javac" depends="resolve">
		<mkdir dir="${build}" />
		<javac srcdir="${src}" destdir="${build}" includeantruntime="false">
			<classpath>
				<fileset dir="${lib}">
					<include name="**/*.jar" />
				</fileset>
			</classpath>
		</javac>
	</target>

4) Make the "compile" target dependent on "compile.aspectj";

	<target name="compile" depends="compile.aspectj">
		<copy todir="${build}">
			<fileset dir="${src}" excludes="**/*.java" />
		</copy>
	</target>

5) Build it.

You might want to also download the AspectJ runtime in your build (e.g. using Ivy).

MongoDB Atlas is the easiest way to run the fastest-growing database for modern applications — no installation, setup, or configuration required. Easily live migrate an existing workload or start with 512MB of storage for free.

Topics:

Published at DZone with permission of Alex Collins. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}