title: Build Managment With Maven and HK2
body: <p>So far, I have created a web application using JAX-RS (<a href="https://jersey.github.io/" rel="nofollow noreferrer">Jersey</a>) and Maven as build and dependency managment, but for this question, I'm not sure it matters. I'm using <a href="https://javaee.github.io/hk2/" rel="nofollow noreferrer">h2k</a> as DI framework. It works fine and I can package the application as a WAR which can be deployed to a tomcat server (both locally and remote).</p>
  
  <p>The application is configured using jersey's ResourceConfig, where I also configure my AbstractBinder (for h2k) to bind my @Inject to concrete instances. So far so good. Now I want to use Jetty (or grizzly) as an embedded server for local development (by mvn jetty:run), and automate the build of the war for remote deployment. I want to use different classes (injected by hk2) depending on the environment (eg. fake email sender, on test server), and this is where I'm stuck. How do I specify which environment I'm running in and how do I specify which classes to use for each environment? </p>
  
  <p>Maybe my problem is in my understanding of how all this works (Examples of actual build setups would be warmly welcomed). Normally I just use <a href="https://en.wikipedia.org/wiki/Abstract_factory_pattern" rel="nofollow noreferrer">AbstractFactory</a>, which I inject into my main method. My guess on how this should be done:</p>
  
  <ul>
  <li>I should create a properties / xml file for each environment, where I specify which implementations and properties should be used.</li>
  <li>When running or building, I should specify which environment I'm running in (for instance mvn build -ENVIRONMENT)</li>
  </ul>