Creating New Java EE 7 Maven Eclipse Project

Still on the Java EE 7 hype, here’s a quick cheat sheet on how to create a minimal Java EE 7 ready maven project:

  1. Ensure you have Eclipse Indigo installed with m2e (maven connector). If not you can drag and drop this logo into running Eclipse instance

    (thanks m2e team)
  2. Create new maven project, tick Create a simple project (skip archetype selection), on the next screen provide Group Id, Artifact Id, and set Packaging to war. Hit Finish
    new maven proj cut
  3. Open pom.xml, switch to source view. Add Java EE 7 dependency. Set the scope to provided so that it is included at compile time, but not on the war bundle (because it should be provided by container)
    
      4.0.0
      com.gerrytan
      jee7fiddle
      1.0
      war
      
      
      
        
          javax
          javaee-api
          7.0
          provided
        
      
    
  4. Tell Maven to compile using JDK 7, otherwise the deafault is JDK 5
      
        
          
          
            maven-compiler-plugin
            3.1
            
              1.7
              1.7
            
          
    
  5. And finally prevent maven-war-plugin from complaining because of missing web.xml. New Java EE 7 style provides good annotation support, web.xml can be omitted for a simple project
          
          
            maven-war-plugin
            2.3
            
              false
            
          
        
      
    
    
  6. Right click on the project -> Maven -> Update Project… -> OK. This will cause m2e to synchronize with all changes we made
  7. Test your new project by running clean package
    maven run cut
    You should end up with a war bundle with your project name under target directory

5 thoughts on “Creating New Java EE 7 Maven Eclipse Project”

  1. Beautiful, I got everything working using this tutorial, also you might mention that cleaning the maven “.m2″ repo might resolve any build issues.

    1. Thanks. The internal maven repository causes problem if you manually insert artifacts into it / there are corrupt files. As long as you’re managing it properly you should never have to delete it.

  2. Many thanks for this tutorial. I could create the maven project but I can not find how to run “clean package”.Would you say in which Eclipse menu or option I can run maven goals?

    Reply
    1. You need to either intstall the maven plugin for eclipse (m2e) and setup a Maven run configuration, or run the maven command line. It might help to spend some time with the maven documentation.

Leave a Reply