Note: See the blog post How I Created a Standard pom.xml file for Eclipse and NetBeans for the final version of the pom.xml
Setting up a Maven project in NetBeans for the purpose of JEE 6 is simpler than Eclipse. I also had a goal of creating a project that will work in NetBeans and Eclipse when loaded from a Subversion repository. Here then are the steps necessary to create a Maven project in NetBeans. See the end of the post to learn how to move projects back and forth between NetBeans and Eclipse.
Step 1
Before you install NetBeans you must have Java installed. You must choose between a 32 and 64 bit version of this download. Here is a recent article on this subject: http://www.javacodegeeks.com/2012/12/should-i-use-a-32-or-a-64-bit-jvm.html . I use the 64 bit JVM.
For NetBeans you want to download the Java EE version 7.4 from http://netbeans.org. NetBeans has a Windows installer that allows you the opportunity to select where it and its servers will be installed when a custom install is chosen. Netbeans wants to place its components in the Program Files folder. I prefer to place NetBeans, Glassfish and Tomcat in folders of my choosing. Typically I place then in folders called NetBeans, Glassfish and Tomcat in the root of a drive. There is an installer for the Mac but there are no choices to be made other than which servers to install. I have not set up NetBeans on Linux.
Step 2
Download and install (unzip into the folder of your choice) TomEE from http://tomee.apache.org/downloads.html . There are three versions but it does not matter which one you choose. I use the web profile version.
Step 3
Run NetBeans. The first task will be to make it aware of Tomee. Select the Services tab usually adjacent to Files and Projects. Right mouse click on Servers to select Add Server…
Step 4
In the Add Server Instance dialog select Apache Tomcat. Next, browse to the Server Location. When I set up Tomee I enabled the manager account that has a default user name of ‘tomee’ and a password of ‘tomee’. Enter these or what you may have changed them to in the appropriate fields. Tomee is now available for projects.
Step 5
Select the Projects tab. From the menu select File -> New Project. In the New Project dialog select Maven -> Web Project. In the New Web Application dialog fill in the usual fields such as Project Name and Group Id. In this last New Web Application dialog screen called settings select your Tomee server and set the Java EE Version to 6.
Step 6
The pom.xml file generated by NetBeans contains elements of significance to command-line Maven. My experiments have shown that the same pom.xml file that I determined was appropriate for Eclipse will work in NetBeans. Therefore you want to replace the portion of the pom.xml file that follows the <name> tag. Here is the complete pom.xml from my previous post. Copy and paste what you need.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.kenfogel</groupId> <artifactId>WebProfileExample</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>Web Profile Example</name> <description>Tutorial Eclipse and TomEE project</description> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.openejb.maven</groupId> <artifactId>tomee-maven-plugin</artifactId> <version>1.6.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> <webXml>src/main/webapp/WEB-INF/web.xml</webXml> </configuration> </plugin> </plugins> </build> </project>
There you have it. The NetBeans environment is ready to use.
Eclipse vs Netbeans
Eclipse generates numerous private files when it creates a project. When an Eclipse project is committed to a repository with Subversion all these files are included. When retrieving this project into NetBeans these Eclipse files are ignored and are not brought into the NB project. Therefore NetBeans is ready to go.
Going from NetBeans to Eclipse requires a bit of extra work because the Eclipse configuration files are missing. Import the project from the repository into Eclipse making sure that Check out as a project in the workspace is selected.
Once the project appears in the Project Explorer right mouse click on the project and select Configure -> Convert to Maven Project. Eclipse will now recognize the project as JEE and generate its configuration files.