title: How to load external file into classpath Play Framework 2.3
body: <p>I have a need to load an <strong>external file</strong> into the classpath using Play Framework 2.3 (Java)</p>
  
  <p>Stipulations:</p>
  
  <ul>
  <li><p>The external file cannot live inside my Play app (i.e. the <code>/conf</code> and <code>/lib</code> directories, etc. are not an option)</p></li>
  <li><p>The file needs to be a <code>.properties</code> or a <code>.conf</code> file so I can specify property values</p></li>
  </ul>
  
  <p>Here's my scenario:<br></p>
  
  <ul>
  <li><p>I have a custom JAR that has some code which is looking for a specific file (let's call it <code>myproperties.properties</code>) in the classpath when being used.  The way that I'm attempting to find <code>myproperties.properties</code> is by doing this inside a class that resides inside that custom JAR:</p>
  
  <pre><code>ClassLoader classLoader = com.my.package.MyCustomJavaClass.class.getClassLoader();
  InputStream inputStream = classLoader.getResourceAsStream("/path/to/myproperties.properties");
  </code></pre>
  
  <p>I have access to change the properties file name and the path to it inside the JAR.</p></li>
  <li><p>My Play Framework App (using Java) has this custom JAR in it's <code>/lib</code> folder, so it gets automatically added to the classpath (this is tested and works correctly).  My Play App calls MyCustomJavaClass when it first loads the <code>/</code> route (index route), so the class loader and input stream code above gets kicked off when I hit my play app in the browser.</p></li>
  </ul>
  
  <p>Problem:</p>
  
  <ul>
  <li><p>I have not been successful in my attempts to load <code>/path/to/myproperties.properties</code> into the classpath when starting the Play App in a way that my code in the custom JAR can see it.</p>
  
  <p>I've been attempting to start play with the classpath command like so in an attempt to feed the JVM the external file:</p>
  
  <pre><code>activator start -J-classpath "-J-classpath:/path/to/myproperties.properties"
  </code></pre>
  
  <p>I'm adding <code>-J-classpath;</code> to the beginning of the path in an attempt to copy everything that's currently in the classpath and then just adding my single, external file.  However, doing this doesn't seem to be working (i.e. my inputStream is null).</p></li>
  </ul>
  
  <p>Questions:</p>
  
  <ul>
  <li><p>Am I doing the <code>activator start -J-classpath</code> command correctly when starting the play app?  Other variations in an attempt to copy the existing classpath first were not allowing the play app to start, but this command at least starts my app.</p>
  
  <p>Reference (Specifying additional JVM arguments):  <a href="https://www.playframework.com/documentation/2.3.x/ProductionConfiguration" rel="nofollow">https://www.playframework.com/documentation/2.3.x/ProductionConfiguration</a></p></li>
  <li><p>What are some other ways that I could possibly get this done?  I've explored overriding the <code>application.conf</code> file using <code>activator start -Dconfig.file=/path/to/application-override.conf</code> and putting my properties inside the new <code>application-override.conf</code> file.  However, it doesn't seem to put that file into the classpath for MyCustomJavaClass to find using the Class Loader.  Maybe I'm doing this command incorrectly as well?</p></li>
  <li><p>Is it possible that somehow the Play Framework classpath is separate from the classpath that my custom JAR is seeing?  I've been under the assumption that it's all in one JVM and classpath.</p></li>
  </ul>