Maven in MyEclipse (Maven4MyEclipse)

1. Maven Integration in MyEclipse

This overview introduces you to the basic concept of what Maven is, and how working with Maven in MyEclipse (Maven4MyEclipse) improves the Maven experience within the UI.

Maven4MyEclipse is equally useful for the novice and Maven guru alike because it makes the most oft-used Maven tasks easy.Maven4MyEclipse is an enhanced integration between Maven (see What is Maven?) and the MyEclipse IDE. Thisintegration removes some of the most common barriers to entry for Maven users, including:

By removing these barriers to entry, you can simply use Maven in MyEclipse with a project, and off you go; no additional headaches or setup to contend with.

2. What is Maven?

In the simplest sense, Maven is a project management tool with a core reputation based around its project-building capabilities. Many regard Maven as only a build tool, but its plugin-based nature (not unlike Eclipse) allows it to function as an end-to-end project management tool, providing a virtually limitless array of features. The variable nature of these plugins leads to some of the confusion around the “What is Maven?” question.

The core design of Maven is built upon dependency management and a single JAR repository. Your project’s library requirements are defined along with other build requirements. Maven follows a strict standard of JAR versioning; the typical myproject.jar convention doesn’t pass muster in the Maven world. It has to be myproject-1.3.7.jar, or at worst myproject-SNAPSHOT.jar. Maven updates those libraries from referenced (public or private) repositories, and each is pulled into your local Maven repostitory as builds are executed. Strict rules are followed as to which local JARs are updated and when, and management can declare these rules as part of the project’s metadata (pom.xml).

Maven projects are defined by Convention Over Configuration. In other words, you don’t define anything ina Maven pom.xml (project definition file) except for what is different from or additional to a standard Maven project. Thus, every project runs the same core phases, which include the many goals included therein. Even additional custom plugins are typically laced into these same phases when a Maven goal runs.

Note: You can read about the Maven Lifecycle from you are an Ant user, this is perhaps the hardest part of Maven to grasp – the idea that you don’t, rather than do, write the core build script. If you’ve done the inverse for five years like most corporate developers, this can be puzzling. Especially since – like Ant – you can still customize a Maven build all you want. You just don’t start out that way. You can even customize it easily, with calls straight into Ant.

3. Using Maven with MyEclipse Projects

The premise behind Maven4MyEclipse is that first and foremost, it’s a MyEclipse project. What this means is that it should work like any MyEclipse project has before, and with and without Maven. All the set ups, the tooling, and general workability of the project should be as any other. Thus, if you never ran a single Maven goal, your project still works the same way. Similarly, your MyEclipse tooling should never have any effect on Maven or the running of its goals.Maven4MyEclipse uses two primary approaches to making common Maven tasks easier.

  • Using wizards to define data easily in the pom.xml, or Maven project metadata.
  • Providing both standard and easily customizable menus for launching the Maven goals you use every day.

Maven4MyEclipse creates projects that conform to legacy MyEclipse  project structures on the source code side. This allows you to code your projects in the same way that you have always done with MyEclipse projects. The classpath containers and compiled binaries are all structured to Maven conventions, so MyEclipse users moving to Maven for the first time have the best of both worlds.

3.1 Projects that Support Maven

Maven4MyEclipse brings Maven support to MyEclipse Web projects, MyEclipse EJB projects, MyEclipse EAR projects, and conventional Java projects.

Maven4MyEclipse creates your Maven-enabled MyEclipse projects to work with both Maven and MyEclipse tooling, simultaneously. Maven-enabled MyEclipse projects function normally as MyEclipse projects, offering all the same tooling that any typical MyEclipse project provides: views, editors, deployment and debugging. None of the tools you have come to rely on have changed. The difference is in the additional tools available to you.

Maven-enabled MyEclipse projects function like MyEclipse projects as well as Maven projects; allowing you to run any Maven goal against them using the MyEclipse IDE, manage dependencies, and more.

Imported Maven projects are automatically configured with appropriate metadata based on information contained in the pom.xml file, making them immediately deployable and usable without additional configuration.

3.2 Java EE Configurators

MyEclipse automatically detects facets for Maven projects based on pom.xml and/or specific configuration files. This makes it possible for imported Maven projects to be usable immediately. It also automatically detects facets at a later stage if you modify pom.xml or add new configuration files. However, you might want to deactivate specific facet configurators to avoid installing unnecessary facets.

Globally per workspace, configurators can be disabled by selecting Window>Preferences, expanding MyEclipse>Maven4MyEclipse>JavaEE Integration. Select the Java EE configurators you want to to be active. All are active by default.

Maven in MyEclipse preferences Active configurators

To deactivate Maven facet configurators for a project, you must include the appropriate property in pom.xml. For example, if you do not want to have the JSF facet installed automatically, open pom.xml, and create the property as shown below:

Maven in MyEclipse POM Configurator deactivation property

The property names for the supported facets are:

JSF – m2e.jsf.activation JAX-RS – m2e.jaxrs.activation JPA – m2e.jpa.activation Struts 1 & 2 – m2e.struts.activation Spring – m2e.spring.activation Hibernate – m2e.hibernate.activation

4. Maven4MyEclipse Compatability with Command-Line Maven

Maven4MyEclipse and Maven-enabled MyEclipse projects perfectly co-exist with command line Maven.

Note: As is the case with any externally-generated artifacts, it is recommended that you refresh your project after an external process like Maven or Ant runs.

Maven4MyEclipse was designed, however, to make command line Maven unnecessary in most instances, allowing you to stay inside the IDE and execute all Maven tasks from the UI.

5. Maven Cautionary Reminder

The MyEclipse team views the addition of the Maven tool set an important step in making the lives of enterprise developers easier, and more effective. This might seem curious, given Maven’s sometimes well earned reputation for frustrating its users at times. We have removed many of the obstacles that normally plague Maven users in the first few hours.

  • Easing the first Maven JAR installs.
  • Making sure your project works perfectly with MyEclipse tooling without ever calling a single Maven goal.
  • Providing reference and tips for most well-known challenges for the Maven initiate.

As a developer, however, you are strongly encouraged to treat the raw power of Maven as you would any new and complex technology. More specifically, Maven can come with some rough edges at times, so budgeting time to deal with these appropriately might be a good idea if you are intending to roll out Maven beyond your workspace to the enterprise level.

Maven’s rough edges are not unwarranted. It is an ever more powerful tool set, and these challenges come with the territory. Some can be dealt with by adding one of several repository tools at the server level, other challenges are addressed as a simpler change of habits or even culture. The many plugins available are also at various stages of maturity, and any single plugin can affect the entire build lifecyle negatively, such as when a plugin is missing from a public repository.

6. FAQ

Do I have to be familiar with Maven to use Maven4MyEclipse?
No, but we would recommend reading Section 2 to become familiar with what Maven is so you can make sense of theMaven features in Maven4MyEclipse.