title: Generating Oozie Workflows using Java Code
body: <p>Looking through Oozie examples and documentation, it looks like you need a workflow file in order to run an oozie job from Java code. Is ther any way to submit a job directly fro Java code, without needing a workflow file? Is there any pre-existing way to dynamically generate these files through java code? Are there any pre-existing tools that will make generating them easier? Or will I have to write the entirety of the code to generate the file?</p>
  
  <p>Current Situation</p>
  
  <pre><code>    OozieClient wc = new OozieClient("http://bar:8080/oozie");
  
      Properties conf = wc.createConfiguration();
      conf.setProperty(OozieClient.APP_PATH, "workflow file path");
      // set other properties
      ...
  
      // submit and start the workflow job
      wc.run(conf);
  </code></pre>
  
  <p>Ideal situation is something vaguely like this.</p>
  
  <pre><code>OozieAction action = new OozieAction("actionName");
  action.setOkDestination("nextAction");
  action.setErrorDestination("errorDestination");
  //Rest of config for action
  
  OozieWorkflow workflow = new Oozieworkflow();
  workfow.setStartAction(action);
  workflow.addAction(otherAction);
  //rest of conf
  
  OozieClient wc = new OozieClient("http://bar:8080/oozie");
  wc.runWorkflow(workflow);
  </code></pre>
  
  <p>Another situation that would be desirable if the former is impossibble is:</p>
  
  <pre><code>OozieAction action = new OozieAction("actionName");
  action.setOkDestination("nextAction");
  action.setErrorDestination("errorDestination");
  
  //Rest of config for action
  
  OozieWorkflow workflow = new Oozieworkflow();
  workfow.setStartAction(action);
  workflow.addAction(otherAction);
  
  //rest of conf
  
  workflow.writeToFile("some localFile")
  
  
  //load file to HDFS
  
  //This would also work
  // workflow.writeToHDFS("someHdfsLocation");
  
  OozieClient wc = new OozieClient("http://bar:8080/oozie");
  
  //run with created workflow
  </code></pre>