title: @PropertySource in a Jar for an external file on the classpath
body: <p>I'm trying to use the Spring framework's <code>@PropertySource</code> annotation in a Jar to load a properties file from outside the jar, but it's not finding the file.</p>
  
  <p>I need the properties file to be external to the Jar so it can be edited. I don't know the exact location where the file will be, I figured I could just have it anywhere on the classpath.</p>
  
  <p>I'm using the following annotation on my <code>Config</code> class.</p>
  
  <pre><code>@PropertySource('classpath:stc.properties')
  </code></pre>
  
  <p>And placed <code>stc.properties</code> in the same directory as the created Jar file. I tried specifying the classpath explicitly in the <code>java</code> command, but it still cannot find the file:</p>
  
  <pre><code>java -cp . -jar stc.jar
  Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.example.stc.Config; nested exception is java.io.FileNotFoundException: class path resource [stc.properties] cannot be opened because it does not exist
          at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:162)
          at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:299)
          at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
          at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
          at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
          at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
  [...]
  </code></pre>
  
  <p>Etc.</p>
  
  <p>I've also tried using <code>./</code> as the classpath, and tried specifying the classpath (with both variants) in the <code>Class-Path</code> attribute of the jar's manifest, but it always gives the same results.</p>