title: How to write main() using CDI in Java EE?
body: <p>I have a no-client application that I wish to run. It will have no clients but it will make HTTP calls and act as client for other services. It would run for perhaps a few hours or days (but it will not require periodic runs -- just one-shot).</p>
  
  <p>I want to run it in a Java EE 7 container, because of the benefits of standard Context Dependency Injection (CD), and a standard JAX-RS client (new since Java EE 7). It is also nice to have services such as JMS, JPA.</p>
  
  <p>The question is how do I write / annotate the main method in a standard way? <code>@Inject</code> on a method is no good because such methods must return quickly. <code>@Schedule</code> is not ideal because it runs periodically unless I programmatically determine current system time.</p>
  
  <p>The best I could come up with is to set a one-shot <code>Timer</code> in an <code>@Inject</code> method and annotate my main method with <code>@Timeout</code>.</p>
  
  <p>Somehow this seems a bit fragile or inelegant. <strong>Is there a better standard way to start the service?</strong> Some annotation that would just cause it to start and get going?</p>
  
  <p>Additionally, how <strong>what is the best standard way to interrupt and shut down the service upon undeployment</strong>?</p>