Tuesday, August 18, 2015

How to create a Hello World with IntelliJ and Aspect J


Since the whole AOP programming method is new to me AND it took me a while to understand how to work with AspectJ and IntelliJ I've decided to create this brief tutorial on how to setup simple Hello World project using AspectJ and IntellJ.

The Ingredients 

  1. IntelliJ Ultimate (I used version 14, you can get it from here: https://www.jetbrains.com/idea/download/)
    1. NOTICE: You must have the ultimate edition. I was not able to use AspectJ with community edition!
    2. I hope you know how to install IntellJ, basically it's next next next.
  2. AspectJ installation (I've used version 1.8.6, you can get the installation JAR here http://www.eclipse.org/downloads/download.php?file=/tools/aspectj/aspectj-1.8.6.jar)
    1. You need to install the jar by double clicking on it in Windows or just run the command from command line 'java -jar aspectj-1.8.6.jar'
    2. NOTICE: Remember where the aspect installtion path since we'll need it later. In windows the default is c:\ (My installation was to c:\aspectj1.8)

So, let's start...


  1. Start the IntelliJ
  2. Click on Create new project
  3. Choose Java project
  4. Don't use template, just click next
  5. Name the project AspectJDemoHelloWorld
  6. Click Finish
  7. Open the settings (in windows Ctrl+Alt+S)
  8. Type compiler in the top search field, Chooe the Java Compiler. You should see something like this
  9. Click on Use compiler and choose Ajc (That is the AspetJ compiler)
  10. Click on the 'Path to Ajc compiler' browse button (near the Test button) and choose the 'aspectjtools.jar' at the lib directory of the AspectJ installation (In my case, C:\aspectj1.8\lib\aspectjtools.jar)
  11. Click on the Test button. You should see something like this 
  12. In the search field, type plugins. You should something like this
  13. Click on the search field inside the plugins window and type AspectJ. Verify both plugins are enabled
  14. Press ok
  15. Open the project preferences (Ctrl + Alt + Shift + S in windows)
  16. Click on Modules in the left navigation pane and then click Dependencies.
  17. Click on the plus sign and choose JARs or directories.
  18. Go to the installation folder of the AspectJ and choose  the file 'aspectjrt.jar'
  19. Press OK.
  20. That's for the configuration part


  1. Go to your src directory
  2. Create a new JAVA class named Hello, Paste in the following
  3. public class Hello {
        public static void main(String[] args) {
        public static void sayHello() {
            System.out.print("Hello ");

  4. Create a new Aspect. Right click and choose Aspect (This ability was enabled due to adding of aspectjrt.jar)
  5. Name the Aspect World and click ok
  6. Paste the following in the aspect

  7. public aspect World {

        pointcut greeting() : execution (* Hello.sayHello(..));
        after() returning() : greeting() {
  8. Click on Build --> Rebuild project
  9. Right click on Hello.java and choose Run
  10. You should see 'Hello World' in the System console
If you only see Hello, that means the Aspect code was not compiled meaning, you should check the Ajc compiler is the compiler chosen (see step 7 in the configuration part)

Thursday, August 13, 2015

Creating javadocs without the package name before objects (with and without ant)


This is a simple one but from some reason it took a while to find the solution.

When creatin javadocs, by default each object comes with it package name.
If you don't want to see the package name before each object, use the noqualifier flag (thanks to http://stackoverflow.com/questions/10766238/javadoc-parameter-without-package-name for the solution)

As ant target

Example Javadoc ant taget

<target name="javadocs" >
    <mkdir dir="${dir.javadocs}"/>

    <javadoc packagenames="com.tzachsolomon.example.*"             sourcepath="-module1/src/main/java:module2/src/main/java"             destdir="${dir.javadocs}"             classpath="module1/src/main/java:module2/src/main/java"
             author="true"             version="true"             use="true"             access="public"             windowtitle="${app.name} API"             encoding="UTF-8"             verbose="false"             noqualifier="all"             doctitle="&lt;h1&gt;${app.name}&lt;/h1&gt;"/>