title: NoClassDefFoundError in org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53
body: <p><strong>NoClassDefFoundError in org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53</strong></p>
  
  <p>I'm developing an AOP logger.  It works fine with a straight up Java class with a main() method but is failing when used in conjunction with Spring Boot.  The logging jar file is in both the bootclasspath and the class path. An exception is thrown even before I'm able to print out the class path.  Am I missing a configuration step to make Spring Boot happy?</p>
  
  <p>The exception:</p>
  
  <pre><code>java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.co.brs.logging.aop.AopLogger
      at com.co.brs.restserver.RestApplication.main(RestApplication.java:73)
      ... 6 more
  </code></pre>
  
  <p>The command line:  </p>
  
  <pre><code>/usr/java/latest/bin/java -Xbootclasspath/p:/usr/local/co/lib/logging-logger.jar -server -cp /usr/local/co/lib/logging-logger.jar:/usr/local/co/bin/../lib/restserver:/usr/local/co/lib/*:/usr/local/co/catalog/lib/*:/usr/local/co/lib/logging-logmanager/* -jar /usr/local/co/bin/../lib/restserver/rest-server.jar &gt;&gt; /usr/local/co/bin/../log/restserver.out 2&gt;&amp;1 &amp;
  </code></pre>
  
  <p>The RestApplication.java:</p>
  
  <pre><code>@Configuration
  @EnableAutoConfiguration
  @ComponentScan({"com.co.brs.restserver.component", "com.co.brs.restserver.service", "com.co.brs.restserver.web", "com.co.brs.restserver.doc"})
  public class RestApplication {
  
      @Value("${keystore.file}") private String keystoreFile;
      @Value("${keystore.pass}") private String keystorePass;
      @Value("${keystore.type}") private String keystoreType;
      @Value("${secure.port}") private String securePort;
  
      /**
       * Start Spring boot Application
       * @throws Exception
       */
      public static void main(String[] args) throws Exception {
  
          ClassLoader loader = RestApplication.class.getClassLoader();  
          System.out.println(System.getProperty("java.class.path"));
          //Get the System Classloader
          ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();
  
          //Get the URLs
          URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();
  
          for(int i=0; i&lt; urls.length; i++)
          {
              System.out.println(urls[i].getFile());
          }       
          SpringApplication restApp = new SpringApplication(RestApplication.class);
          restApp.setShowBanner(false);
          restApp.setDefaultProperties(new HashMap&lt;String, Object&gt;());
          ApplicationContext context = restApp.run(args);
          RestService restService = context.getBean(RestService.class);
          restApp.setRegisterShutdownHook(true);
  
          // Start component
          if (!restService.start()) {
              // Failed to start
              System.out.println("Failed to start - exiting\n");
              System.exit(SpringApplication.exit(context, new JobExecutionExitCodeGenerator()));
          }
          System.out.println("Rest Service is up and running");
      }
  </code></pre>
  
  <p>And the AOP Logger snippet:</p>
  
  <pre><code>pointcut logMethod():
      (execution(public * *(..)) &amp;&amp; !execution(public * get*(..)) &amp;&amp; !execution(public void set*(..)) 
              &amp;&amp; !cflow(adviceexecution() &amp;&amp; !execution(public com.co.brs.logging* *(..))));
  
  before(): logMethod() {...}
  </code></pre>
  
  <p>The pom.xml file includes the following dependencies:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.co.brs.logging&lt;/groupId&gt;
      &lt;artifactId&gt;logging-logger&lt;/artifactId&gt;
      &lt;version&gt;${project.version}&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
      &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
      &lt;version&gt;1.8.2&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-aop&lt;/artifactId&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I updated the point cut in the AOPLogger to ignore main() methods and got farther.</p>
  
  <p>The point cut:</p>
  
  <pre><code>pointcut logMethod():
      (execution(public * *(..)) &amp;&amp; !execution(public * get*(..)) &amp;&amp; !execution(public void set*(..))  &amp;&amp; !execution(public void main(..)) 
              &amp;&amp; !cflow(adviceexecution() &amp;&amp; !execution(public com.co.brs.logging* *(..))));
  </code></pre>
  
  <p>New output:  (The code is getting into the execution:</p>
  
  <pre><code>java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.NoClassDefFoundError: org/aspectj/runtime/reflect/Factory
      at com.co.brs.logging.CatalogHandler.ajc$preClinit(CatalogHandler.java:1)
      at com.co.brs.logging.CatalogHandler.&lt;clinit&gt;(CatalogHandler.java:1)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
      at java.lang.Class.newInstance(Class.java:433)
      at java.util.logging.LogManager$5.run(LogManager.java:966)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.util.logging.LogManager.loadLoggerHandlers(LogManager.java:958)
      at java.util.logging.LogManager.initializeGlobalHandlers(LogManager.java:1578)
      at java.util.logging.LogManager.access$1500(LogManager.java:145)
      at java.util.logging.LogManager$RootLogger.accessCheckedHandlers(LogManager.java:1667)
      at java.util.logging.Logger.getHandlers(Logger.java:1776)
      at org.slf4j.bridge.SLF4JBridgeHandler.removeHandlersForRootLogger(SLF4JBridgeHandler.java:169)
      at org.springframework.boot.logging.log4j.Log4JLoggingSystem.beforeInitialize(Log4JLoggingSystem.java:64)
      at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:135)
      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)
      at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100)
      at org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:54)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:276)
      at com.emc.brs.restserver.RestApplication.main(RestApplication.java:62)
      ... 6 more
  </code></pre>