title: Spring context from within a jar file
body: <p>I'm developing a desktop application in java using spring and hibernate. I want to package it as a executable jar but I'm having problems loading the context configuration XML from within the jar file.</p>
  
  <p>I package the application as a runnable jar file and when I run the jar file it tells me that the file doesn't exist. I know that from within a jar file I should load an InputStream but there's no ApplicationContext implementation that supports it.</p>
  
  <p>I believe that I'll have to code my own InputStreamXmlApplicationContext and I already tried doing it. I did some research and a little coding:</p>
  
  <pre><code>
  import java.io.InputStream;
  
  import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
  import org.springframework.context.support.AbstractXmlApplicationContext;
  import org.springframework.core.io.InputStreamResource;
  import org.springframework.core.io.Resource;
  
  public class InputStreamXmlApplicationContext extends AbstractXmlApplicationContext {
  
      private Resource[] configResources;
  
      public InputStreamXmlApplicationContext(InputStream in) {
          InputStreamResource resource = new InputStreamResource(in);
          configResources = new InputStreamResource[] {resource};
          setConfigResources(configResources);
          refresh();
      }
  
      public Resource[] getConfigResources() {
          return configResources;
      }
  
      public void setConfigResources(Resource[] configResources) {
          this.configResources = configResources;
      }
  
      protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) {
          beanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
      }
  }
  </code></pre>
  
  <p>But I can't get it to work. Could someone help me?</p>