title: Could not load JDBC driver class - Spring Batch standalone program
body: <p>I'm working on a Spring Batch program, running it as a command-line app (currently via STS for testing).  When I run it via the Eclipse run/debug configuration via the org.springframework.batch.core.launch.support.CommandLineJobRunner, it cannot load the SQL Server JDBC driver.  I'm certain I have it on the classpath, but evidently it is still having issues.</p>
  
  <p>Here is my exception trace from the console log:</p>
  
  <pre><code>09:11:59.291 [main] ERROR o.s.b.c.l.s.CommandLineJobRunner - Job Terminated in error: Error creating bean with name 'legacyDatasource' defined in class path resource [META-INF/spring/module-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
  PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.microsoft.jdbc.sqlserver.SQLServerDriver]
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'legacyDatasource' defined in class path resource [META-INF/spring/module-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
  PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.microsoft.jdbc.sqlserver.SQLServerDriver]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1506) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:290) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
      at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:590) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
  Caused by: org.springframework.beans.PropertyBatchUpdateException: Failed properties: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.microsoft.jdbc.sqlserver.SQLServerDriver]
      at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1502) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
      ... 14 common frames omitted
  </code></pre>
  
  <p>My datasource config from the spring xml (details changed to protect the innocent of course):</p>
  
  <pre><code>&lt;bean id="legacyDatasource" class="org.springframework.jdbc.datasource.SingleConnectionDataSource"&gt;
    &lt;property name="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" /&gt;
    &lt;property name="url" value="jdbc:microsoft:sqlserver://server:1433;DatabaseName=database" /&gt;
    &lt;property name="username" value="user" /&gt;
    &lt;property name="password" value="pw" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now to the classpath stuff...installed in my local maven repo:</p>
  
  <p><img src="https://i.stack.imgur.com/1S0iD.png" alt="enter image description here"></p>
  
  <p>And in my pom:</p>
  
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;com.microsoft.sqlserver&lt;/groupId&gt;
    &lt;artifactId&gt;sqljdbc41&lt;/artifactId&gt;
    &lt;version&gt;4.1&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>And it's in my project's Maven Dependencies:</p>
  
  <p><img src="https://i.stack.imgur.com/8o0pE.png" alt="enter image description here"></p>
  
  <p>In my run config, I've tried adding it directly to the classpath on the classpath tab, and through the VM argument.</p>
  
  <p><img src="https://i.stack.imgur.com/4KFDA.png" alt="enter image description here"></p>
  
  <p>I'm pretty sure it's something simple.  Any ideas why the driver cannot be loaded?  To me it's also worth noting that it's not a class not found error (though it may be under the covers and not part of this stack trace).</p>