title: how to add a file to Java Classpath at Runtime?
body: <p>I am creating a feature file at runtime and trying to access the file once it is created . I have followed all the methods given  <a href="https://stackoverflow.com/questions/1010919/adding-files-to-java-classpath-at-runtime">here</a> . </p>
  
  <pre><code> 1. Is there a way to refresh the project at runtime ?
   2. Is there any other way to load the file in classpath ?
  </code></pre>
  
  <p>[Edit] Adding Sample code</p>
  
  <pre><code>  public static void createFeatureFile(String featurePath) throws IOException{
  
      FileWriter writer = new FileWriter(featurePath);
  
      writer.append("Feature: Test ");
      writer.append("\n");
      writer.append("\n");
      writer.append("@test");
      writer.append("\n");
      writer.append("Scenario : add fruits");
      writer.append("\n");
      writer.append("Given I have 1 apple and 1 orange");
      writer.append("\n");
      writer.append("Then I add both"");
      writer.append("\n");                    
  
      writer.flush();
      writer.close();    
  
      File file =new File(featurePath);
      addFileAtRunTime(file);           
  
  }
  
    private static void addFileAtRunTime(File file) throws Exception {
          Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
          method.setAccessible(true);
          method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{file.toURI().toURL()});
      }
  </code></pre>