title: Why do my aspects get executed in their original setting and not when packed as a separate jar and called from elsewhere?
body: <p>I am a newbie to aspectj... </p>
  
  <p>I have written the following aspect which is intended to add logging to function calls of type <code>public * doSomething*(..)</code>. If my main class is part of the same project the weaving of the aspect is performed without a glitch and the code executes. If I pack up the weaved code into a jar and call it from another eclipse project - the advice is not executed. Another scenario is packing up the aspect (.aj) only into a separate jar and adding that jar to the "Aspect Path" in eclipse, this enables eclipse to weave the aspect properly. Thing is I need to wrap this up into a jar and call the code from elsewhere. That doesn't work either (Not surprisingly I presume...) Why? </p>
  
  <pre><code>import org.aspectj.lang.JoinPoint;
  import org.aspectj.lang.reflect.CodeSignature;
  import org.apache.log4j.Logger;
  
  public aspect Logging {
      pointcut allPublic(): !cflow(call(public void main(..))) &amp;&amp; (call(public * doSomething*(..)));
  
      private static final Logger log = Logger.getLogger("Logging.aspect");
  
      @SuppressWarnings({"unchecked", "unused"})
      private void printParameters(JoinPoint jp) {
          CodeSignature methodSignature = (CodeSignature) jp.getSignature();
          String methodName = methodSignature.getName();
          Object[] paramNames = methodSignature.getParameterNames();
          Class[] paramTypes = (Class[])methodSignature.getParameterTypes();
          Object[] paramObjects = jp.getArgs();
          StringBuffer infoMsg = new StringBuffer();
  
          infoMsg.append("Entering function: " + methodName);
          if (paramNames != null &amp;&amp; paramNames.length &gt; 0){
              if (paramNames.length == 1){
                  infoMsg.append(" with input parameter: ["+ paramNames[1]+ "] = [" + paramObjects[1] + "]");
              }
              else {
                  infoMsg.append(" with input parameters: ");
              }
              for (int i = 1; i &lt; paramNames.length; i++) {
                  infoMsg.append(" [" + paramTypes[i].getName() + " " + paramNames[i]+ "] = [" + paramObjects[i] + "]");
              }
          }
          else {
              infoMsg.append(" NONE");
          }
         log.info(infoMsg.toString());
  
      }
  
      @SuppressWarnings("unused")
      private void printExit(JoinPoint jp) {
          log.info("Exit function: " + jp.getSignature().toString());
      }
  
      before() : allPublic() {
          printParameters (thisJoinPoint);
      }
  
      after() : allPublic() {
          printExit(thisJoinPoint);
      }
  }
  </code></pre>
  
  <p>The class which is supposed to be advised:</p>
  
  <pre><code>public class Main {
  
      private static final Logger log = Logger.getLogger("A.class");
  
      public static void doSomethingAa(int number, String message, Map&lt;String, String&gt; map){
          log.debug("A");
      } 
  
      public static void doSomethingB(int id, String name){
          log.debug("B");
      }
  
      public static void main(String[] args){
          Map&lt;String, String&gt; map1 = new TreeMap&lt;String, String&gt;();
          Map&lt;String, String&gt; map2 = new TreeMap&lt;String, String&gt;();
  
          map1.put("FirstKey", "FirstValue");
          map1.put("SecondKey", "SecondValue");
  
          map2.put("Tal", "Guy");
          map2.put("Happy", "Birthday");
  
          A.doSomethingAa(17, "Tal", map1);
          A.doSomethingAa(35, "Guy", map2); 
  
          A.doSomethingB(12, "TalG");
          A.doSomethingB(40, "GuyG");
  
          System.out.println("Finished running main");
  
      }
  
  }
  </code></pre>
  
  <p>Thanks all!</p>