title: Programmatically refreshing a file in an eclipse Java application
body: <p>I have the following program which adds a method to itself when run. But  I have to refresh it every time using the F5 button or the refresh option.
  <strong>Is there a way I could code the refresh in the program itself</strong> so that it refreshes itself after the modification? The project I am working on is a Java application and not an eclipse plugin so as far as I know the refreshLocal() method can't be used.</p>
  
  <pre><code>public class Demo {
  public static void main(String[] args) throws IOException, CoreException {
      File file = new File("/home/kishan/workspace/Roast/src/Demo.java");
  
      if (file.exists()) {
          JavaClassSource javaClass = Roaster.parse(JavaClassSource.class,
                  file);
          javaClass.addMethod().setPublic().setStatic(true)
                  .setName("newMethod").setReturnTypeVoid()
                  .setBody("System.out.println(\"newMethod created\");")
                  .addParameter("String[]", "stringArray");
          FileWriter writer = new FileWriter(file);
          writer.write(javaClass.toString());
          writer.flush();
          writer.close();
  
      }
  
  }
  }
  </code></pre>
  
  <p>I have tried using the refreshLocal() method defined in the eclipse JDT but since my project is a Java application the ResourcePlugin.getWorkspace() method does not work giving me a "workspace closed" error.<br> Any suggestion is appreciated. </p>