Viadeo

Antoine Sabot-Durand

Pages

J'ecoute les Cast Codeurs

WTP + M2eclipse + Seam : Maven works !

 français 

Lucky me ! It’s only now that I need that one of my Seam project works with Eclipse WTP and Maven. Lucky because a few months ago, that tutorial would have been impossible to write. This article will show how to adapt a JEE5 project in order to make it usable with Eclipse WTP and Maven.

Starting the tutorial

We start this tutorial with 3 Eclipse projects : an EAR, an EJB and a WAR project. These projects are showed in the following picture

figure 1 : les trois projets sous Eclipse et WTP

The 3 projects are linked with the Eclipse configuration files which contains informations about EAR, EJB and WAR projects. In this article the projects are based on JBoss Seam, but all the tutorial could be used in any project type.

On the disk, the 3 projects are 3 directories in the workspace folders. Useless to say it’s not the Maven way to organize projects.

Creation of the parent Project

First step, we create a Maven parent project which will contain our EAR, EJB and WAR projects (that Maven call modules). In this parent project we can define global parameters for the modules. To create this project click on “File/New/Porject…”

ChooseMavenProject

Choose Maven Project in the Maven category and click on Next, this opens the “New Maven Project” wizard :

New Maven Project 1

You can go to the next step after checking that “Create a simple project” is unchecked.

Choose Archetype

In this dialog box you have to choose an archetype (a template for your project). In Catalog choose Nexus Indexer which brings a richer list than the internal default one. In the filter field enter “pom” to reach the “pom-root” archetype”. Select it and click on “Next”.

Maven Project Name

In this last dialog box you choose the project name. click on “Finish”. Now you have a new project in your workspace. In my case it’s “pfm77-parent”

Creating the Maven modules

In the same way we created parent project, we’re going to create the children projects or modules. click on “File/New/Project…”

Choose Maven Module

Choose “Maven Module” then click on “Next”. A new wizard opens :

create ear module

Enter the name for the EAR module and the name of the parent project then click on “Next.

Archetype EAR

Don’t forget to choose “Nexus Indexer” in the catalog, enter “ear” in the filter field. Choose the “ear-jee5″ archetype then click on “finish”

To create the EJB and WAR modules, we’ll use the same wizard choosing archetypes “ejb-jee5″ and “webapp-jee5″.

After all those wizards and clicks, we have 4 new projects in the workspace :

projets maven créés

The physical structure of these Eclipse projects are different. If you look on your disk, you’ll see a Maven hierarchy (a main project and modules in in the folder of the main project). It’s one of the m2eclipse benefits : supporting sub-projects in Eclipse. But it’s not the only advantage of the plugin.

Benefits of m2eclipse

1) Managing sub-projects in Eclipse

As we saw, you can have a Maven hierarchy that m2eclipse make look likes different Eclipse project in the IDE. This also works when you import existing maven project in the worskpace from the disk or versioning system.

2) Managing Maven dependencies

The plugin use the pom.xml files to download and add jar files in your project.

3) Maven build in Eclipse

The least we can wait for this plugin. A m2eclipse project has 2 builders : the standard Eclipse one and the maven one.

4) A nice user interface to manage pom.xml files

You can use this interface to look for dependencies or exclude a sub-dependency easily. It was rather bugy in the past but with version 0.99 of m2eclipse it starts to be very usefull.

5) Automatic management of Eclipse projects configuration

That’s an important benefit that is not very well documented on m2eclipse site. M2eclipse uses pom.xml information to generate and maintain Eclipse configuration files for the project. For instance the projects we just created are not Eclipse project. They were created from Maven Archetypes that have nothing to do with Eclipse. So the eclipse configuration files of these new project (.classpath, .project files and .settings folder) were generated by m2eclipse from the pom files. When pom files are modified, m2eclipse will change Eclipse configuration files automatically. For instance, let’s have a look at the Facets of the EJB project (right-click on the project, and choose properties/facets) :

project facets

M2eclipse have added this EJB3 facets by analyzing the pom.xml file. So if you change Eclipse configuration on the project there can be some chance that you touch a configuration driven by m2eclipse. So take care of your modification. To be sure you won’t go battle wth m2eclipse in the configuration you should check the m2eclipse documentation. This page show all the Maven parameters (with green checkboxes) that are used by m2eclipse to build and maintain Eclipse WTP configuration files.

To finish with this point, you’ll have to be extremely carrefull when you put those project under versioning system. The best solution is to ignore Eclipse configuration files and let m2eclipse do the job on the other systems (you’ll have to create local configuration on each IDE to configure information that are not in Maven files like deploying servers for instance).

Copying Files

Let’s go back to our tutorial : moving WTP projects to maven/WTP projects. The next step consist to copy files from our old WTP project to the newly created Maven/WTP projects. You can do this by dragging files from file system (Explorer, Finder, or whatever you use) to Eclipse using the “resources” perspective which is the more close to filesystem perspective. To keep it simple try to stick with the default Maven layout, It will make pom files lighter.

  • For the EAR module you’ll put the content of META-INF in src/main/application/META-INF all the other files in te project will be build from pom.xml
  • For the EJB module, all your classes should be put in src/main/java, resources files like properties or META-INF folder should be in src/main/resources.
  • For the WAR module you’ll use the same folders as EJB for classes and resources. The site files will be copied in src/main/webapp folder (be carefull and don’t take the WEB-INF/lib folder)

You should ignore Manifest files in all the project because they can cause runtime errors.

Now we have to deal with our pom files

Pom pom pom pom

It’s not a symphony but almost (sorry for that). The setting of our 4 pom.xml files will ask some patience (it’s the Maven feng-shui side) but we will get trough.

Parent project

I won’t detail all my pom.xml files content : I want to keep my readers till the end. Instead I’ll show you the result and comment the main part of each file

  • Introduction : here I tell Maven that it is a pom project that drive construction of sub-projects (modules).
  • modules : here are the modules contained by this parent project.
  • properties : here I define variables that will be used in configuration of all the modules (libraries version for instance)
  • repositories : in this section I add Maven repositories used by my project. For me it’s JBoss repositories for Seam and java.net to get all Jee5 dependencies
  • dependencyManagement : In this part, I declare all the dependencies used by my modules. Declaring them here, I can set their version once for all.
  • build : in this final section I can set up compilation configuration once for all.

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>cos</groupId>
  <artifactId>pfm77-parent</artifactId>
  <packaging>pom</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>pfm77-parent Multi Project</name>
  <url>http://maven.apache.org</url>
  <modules>
    <module>pfm77-ear</module>
    <module>pfm77-ejb</module>
    <module>pfm77-war</module>
  </modules>

  <properties>
    <seam.version>2.0.3.CR1</seam.version>
    <jsf.version>1.2_10</jsf.version>
    <richfaces.version>3.2.1.GA</richfaces.version>
  </properties>

  <repositories>
    <repository>
      <id>jboss</id>
      <name>JBoss Repository</name>
      <url>http://repository.jboss.org/maven2</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
    <repository>
      <id>jboss-snapshots</id>
      <name>JBoss Snapshot Repository</name>
      <url>http://snapshots.jboss.org/maven2</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
    <repository>
          <id>java.net1</id>
          <name>Java.Net Maven1 Repository, hosts the javaee-api dependency</name>
          <url>http://download.java.net/maven/1</url>
          <layout>legacy</layout>
      </repository>
  </repositories>

 <dependencyManagement>
 <dependencies>

  <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <version>1.8.0</version>
      <scope>compile</scope>
       </dependency>
        <dependency>
      <groupId>org.ostermiller</groupId>
      <artifactId>utils</artifactId>
      <version>1.07.00</version>
      <scope>compile</scope>
    </dependency>
    </dependencies>
 </dependencyManagement>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>

    </plugins>
  </build>

</project>

EAR project

In the pom file, we can get rid of compilation plug-in because we configured it in the parent project. But we’ll have to add all the depending jars and their version. The m2eclipse auto-completion tools are very usefull for this. Right-click on the project and choose “Maven/add Maven dependency”. The following dialog box opens

Image 10

With this box you can search in Maven repositories the right jar and version for your project and add it the pom.xml file. With time some sub-depencies can appear in the project. You can exclude them by using the “Dependency graph” in pom editor. This view show a graph like this one :

dependency graph

If yo want to exclude a jar you can do it via the context menu and choosing “Exclude Maven Artefact…” (wasn’t working in version 0.98 of m2eclipse). Now, back to our pom file of EAR module here are its content

  • header : I specify that it’s an EAR module and I don’t forget to point to the Parent project
  • In the dependencies I don’t forget EJB and War modules
  • In the build section I add the Maven EAR plugin. In the configuration of the plugin I give the directory where to put the lib and ask Maven to generate my application.xml file
  • In the modules section of the plugin, I add my EJB and WAR modules that I defined at the beginning of the file as dependencies

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>pfm77-parent</artifactId>
    <groupId>cos</groupId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <groupId>cos</groupId>
  <artifactId>pfm77-ear</artifactId>
  <packaging>ear</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>pfm77-ear JEE5 Assembly</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>cos</groupId>
      <artifactId>pfm77-ejb</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <type>ejb</type>
      <scope>compile</scope>

    </dependency>
    <dependency>
      <groupId>cos</groupId>
      <artifactId>pfm77-war</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <type>war</type>
      <scope>compile</scope>

    </dependency>

    <dependency>
      <groupId>org.jboss.seam</groupId>
      <artifactId>jboss-seam</artifactId>
      <version>${seam.version}</version>
      <type>ejb</type>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>javax.el</groupId>
          <artifactId>el-api</artifactId>
        </exclusion>
        <exclusion>
          <artifactId>javassist</artifactId>
          <groupId>javassist</groupId>
        </exclusion>
        <exclusion>
          <artifactId>dom4j</artifactId>
          <groupId>dom4j</groupId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.ostermiller</groupId>
      <artifactId>utils</artifactId>
    </dependency>

    <dependency>
      <groupId>org.richfaces.framework</groupId>
      <artifactId>richfaces-api</artifactId>
      <version>${richfaces.version}</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <artifactId>commons-collections</artifactId>
          <groupId>commons-collections</groupId>
        </exclusion>
        <exclusion>
          <artifactId>commons-logging</artifactId>
          <groupId>commons-logging</groupId>
        </exclusion>
      </exclusions>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <version>5</version>
          <defaultLibBundleDir>lib</defaultLibBundleDir>
          <generateApplicationXml>true</generateApplicationXml>

          <modules>
            <ejbModule>
              <groupId>cos</groupId>
              <artifactId>pfm77-ejb</artifactId>
            </ejbModule>
            <ejbModule>
              <groupId>org.jboss.seam</groupId>
              <artifactId>jboss-seam</artifactId>
            </ejbModule>
            <webModule>
              <groupId>cos</groupId>
              <artifactId>pfm77-war</artifactId>
              <contextRoot>PFM77</contextRoot>
            </webModule>
          </modules>

        </configuration>
      </plugin>
    </plugins>
    <finalName>pfm77-ear</finalName>
  </build>

</project>

EJB project

Next step the EJB pom file. Not a lot of things to say about it except concerning the Maven EJB plugin which is used to set the EJB version.

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>pfm77-parent</artifactId>
    <groupId>cos</groupId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <groupId>cos</groupId>
  <artifactId>pfm77-ejb</artifactId>
  <packaging>ejb</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>pfm77-ejb JEE5 EJB</name>
  <url>http://maven.apache.org</url>
  <dependencies>

    <dependency>
      <groupId>javaee</groupId>
      <artifactId>javaee-api</artifactId>
      <version>5</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.seam</groupId>
      <artifactId>jboss-seam</artifactId>
      <version>${seam.version}</version>
      <scope>provided</scope>

    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-annotations</artifactId>
      <version>3.2.0.ga</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.ostermiller</groupId>
      <artifactId>utils</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
    	<groupId>mysql</groupId>
    	<artifactId>mysql-connector-java</artifactId>
    	<version>5.1.6</version>
    	<scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ejb-plugin</artifactId>
        <version>2.1</version>
        <configuration>
          <ejbVersion>3.0</ejbVersion>

        </configuration>
      </plugin>
    </plugins>
    <finalName>pfm77-ejb</finalName>
  </build>
</project>

WAR project

Last but not least the WAR pom file. Notice that we’re not using Maven war plugin in this pom file, the default values of War packaging are enough.

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>pfm77-parent</artifactId>
    <groupId>cos</groupId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <groupId>cos</groupId>
  <artifactId>pfm77-war</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>pfm77-war JEE5 Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.jboss.seam</groupId>
      <artifactId>jboss-seam-ui</artifactId>
      <version>${seam.version}</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>org.jboss.seam</groupId>
          <artifactId>jboss-seam</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.jboss.seam</groupId>
      <artifactId>jboss-seam-debug</artifactId>
      <version>${seam.version}</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>org.jboss.seam</groupId>
          <artifactId>jboss-seam</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.jboss.seam</groupId>
      <artifactId>jboss-seam-pdf</artifactId>
      <version>${seam.version}</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>org.jboss.seam</groupId>
          <artifactId>jboss-seam</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.richfaces.ui</groupId>
      <artifactId>richfaces-ui</artifactId>
      <version>${richfaces.version}</version>
    </dependency>

    <dependency>
      <groupId>org.richfaces.framework</groupId>
      <artifactId>richfaces-impl</artifactId>
      <version>${richfaces.version}</version>
      <exclusions>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
        <exclusion>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
        </exclusion>
        <exclusion>
          <groupId>javax.faces</groupId>
          <artifactId>jsf-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.richfaces.framework</groupId>
          <artifactId>richfaces-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>javax.servlet</groupId>
          <artifactId>servlet-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>javax.faces</groupId>
          <artifactId>jsf-impl</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

  </dependencies>
  <build>

    <finalName>pfm77-war</finalName>
  </build>
</project>

Generating Eclipse configuration

Now that we have our pom files, we’ll ask m2eclipse to refresh eclipse config files by accessing the “Maven/update configuration file” in the context menu of each project. Doing this refresh .classpath, .project files and .settings folder of our projects.

First Maven build and first fix

From the context menu of the parent project (not the EAR), choose “Run as…/Maven install” or “Maven package”. Maven is launched but the build fails. Don’t panic this issue is caused by a conflict in Maven resolution and Workspace resolution. Disable Worksapce resolution in the parent project by choosing “Maven/Disable Workspace Resolution” in contextual menu of the parent project. Launch the build again and “voila”. You get an ear file in the target directory of the EAR project. In command line you’ll have to launch “mvn install” from parent project folder to have the same result.

What about WTP ?

Before using WTP to deploy your project you’ll have to copy the application.xml file from the target folder (of the EAR project) to the “src/main/application/META-INF” folder and do it again each time EAR modules change (which is not so often). And now ? Beleive it or not but it’s over and it works. In the server view choose your server (if you don’t have one you can create a “local deployer”). In the contextual menu choose “Add remove…” and add your project.

Deployment

Then click on “publih” and tadaaa, your project is deployed with WTP (if it’s not, you just have to restart all this tutorial over :-) ). The only issue is a WEB-INF directory in the root of the EAR which contains a copy of the lib directory of the good WEB-INF directory of the war module. This problem should be harmless for a local deployment and is caused by this Eclipse bug.

Conclusion

So m2eclipse is not working out of the box with WTP project. However it’s a powerfull tool even without this need. About Seam and Maven, JBoss is working on making developer life more simple. JBoss tools 3.1 should include extensions to ease the work with m2eclipse and Seam and Seam 3.0 should be totally mavenized, so easier to be build with Maven.

We’ll keep an eye on it…

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Netvibes
  • Twitter
  • dadoonet95
    Excellent article. Clair didactique. Bravo. (Ok, j'arrive 9 mois après la bataille ;-) )

    Pour ma part, je rencontre un petit souci désagréable lorsque sur un projet WAR, je laisse l'option "Enable Workspace Resolution". Bizarrement les JAR des autres modules fabriqués "à la volée" ne sont pas corrects (1Ko et quasiment vides).
    Du coup, je ne peux pas profiter de cette option et je suis obligé de faire des Install sur les projet JARS et des "Update Snapshots" sur le projet WebApp.
    Tu as déjà rencontré ce type de problème lors de tes expériences ?
  • Pas de problème pour l'arrivée tardive. J'ai moi même laissé un peu en friche mon Blog ces derniers mois. J'espère pouvoir changer ça bientôt.
    Concernant cet article il faudrait que je le revoie car entre temps m2eclipse 0.10 et un certain nombre de manœuvre de contournement décrites ici n'ont plus lieu d'être.
    Malheureusement ton problème ne me dit rien. Tu as essayé de builder ton projet une fois en ligne de commande avec un mvn install ?
  • dadoonet95
    La version 0.10... J'hésite encore à faire la pas vu les discussions sur la mailing liste qui semblent indiquer quelques soucis et le fait que la désinstallation de la version précédente n'est pas super triviale. Bref, je n'ai pas trop le temps en ce moment de me pencher la dessus, mais j'espère faire ça rapidement. Car ça pourrait peut-être résoudre mon problème aussi !
    Oui. Le build normal fonctionne très bien. Mes livrables sont corrects.
    Je ne sais pas trop quel est le maillon de la chaine qui me pose problème : Maven, M2Eclipse, WTP, Eclipse ????
    Un collègue sur un autre projet qu'utilise aussi Maven/M2Eclipse, n'a aucun souci. Les JARs générés en tant que module présents dans le workspace sont corrects.

    Je vais peut-être tenter de me refabriquer un Eclipse vierge avec M2Eclipse 0.10 pour voir si ça change quelque chose...
  • Kwame
    Article très intéressant .
    Bravo, mais please: voulez vous mettre en ligne le code
    source.
    Celà nous éviterait d'avoir à tout retaper.
    Merci d'avance,
    Kwame.
  • Fred Bricon
    Pour automatiser la génération du fichier application.xml -ainsi que la conf jboss-app.xml si besoin- (en attendant que le probleme soit réglé sur m2e 0.9.9), voici quelques conseils :
    * définir dans la conf de maven-ear-plugin :
    <generateddescriptorlocation>${basedir}/src/main/application/META-INF</generateddescriptorlocation>

    * définir une configuration d'execution :
    - click droit sur le projet ear > Run > Maven Build ...
    name=generate-application-xml
    Base directory : remplacer eventuellement le nom du projet par ${project_loc} pour rendre la conf portable entre projets
    goals = ear:generate-application-xml
    cocher "skip tests", "resolve workspace artifacts"

    Dans l'onglet refresh :
    cocher Refresh resources upon completion,
    sélectionner : project containing the selected resource

    dans l'onglet common :
    save as : shared file -> browse -> sélectionner le projet ear

    Cliquer sur apply, un fichier generate-application-xml.target est généré a la racine du projet ear.

    Pour les feignasses près du radiateur, vous pouvez aussi creer ce fichier à la mano avec un éditeur de texte et copier ce qui suit dedans :

    <launchconfiguration type="org.maven.ide.eclipse.Maven2LaunchConfigurationType">
    <booleanattribute key="M2_DEBUG_OUTPUT" value="false">
    <stringattribute key="M2_GOALS" value="ear:generate-application-xml">
    <booleanattribute key="M2_NON_RECURSIVE" value="false">
    <booleanattribute key="M2_OFFLINE" value="false">
    <stringattribute key="M2_PROFILES" value="">
    <listattribute key="M2_PROPERTIES">
    <stringattribute key="M2_RUNTIME" value="EMBEDDED">
    <booleanattribute key="M2_SKIP_TESTS" value="true">
    <booleanattribute key="M2_UPDATE_SNAPSHOTS" value="false">
    <booleanattribute key="M2_WORKSPACE_RESOLUTION" value="true">
    <stringattribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}">
    <stringattribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc}">
    </stringattribute></stringattribute></booleanattribute></booleanattribute></booleanattribute></stringattribute></listattribute></stringattribute></booleanattribute></booleanattribute></stringattribute></booleanattribute></launchconfiguration>

    Une fois le fichier créé, click droit dessus, run as > generate-application-xml
    Le goal de génération de fichiers de conf du plugin ear va s'executer puis le workspace est rafraichi et les fichiers apparaissent à la bonne place.

    Fred.
  • Merci Fred pour ces précisions. Il semblerait que beaucoup d'évolutions sont en cours sur m2eclipse en ce moment (l'équipe de JBoss Tools collabore activement avec Sonatype sur le sujet). On peut espérer avoir une version de m2eclipse avec n peu moins de bricolage dans quelques semaines.
  • Fred Bricon
    Oui je sais, je suis bien placé pour le savoir, devine qui s'en occupe? ;-P
  • Ravi d'avoir un des contributeurs sous la main ;-). Ca avance bien ?
  • Fred Bricon
    Ca avance ... aussi vite que mon temps libre le permet. La gestion de l'application.xml a l'air de marcher, le prochain dev build devrait permettre de jouer avec (je ne sais pas quand il sera dispo). Pour le jboss-as.xml, c'est en cours. Faut rester à l'ecoute de la mailing list (http://www.nabble.com/The-impedance-mismatch-between-WTP-and-Maven-td25020311i40.html) et rester patient.
  • Fred Bricon
    Je parle du jboss-app.xml bien sûr!
  • Merci Fred. Je confirme que le dernier build est beaucoup plus stable que lorsque j'ai écrit cet article.
  • Oscar Picasso
    Pour le point 2 j'ai trouvé. C'était effectivement un problème de nom dans mon maven-ear-plugin.
  • Oscar Picasso
    C'est un article très intéressant. J'ai quelques questions toutefois.

    1- J'ai moi-même essayer plusieurs configuration seam + m2eclipse et j'ai souvent noté des problèmes de stabilité. Est-ce que vous utilisez cette configuration de manière intensive sans problèmes de stabilité.

    2- Avec votre configuration j'ai toujours la même erreur lorsque je fait un build:
    Build errors for my-app-ear; org.apache.maven.ProjectBuildFailureException: Build for project: axa.webapps.my-app:my-app-ear:ear:0.0.1-SNAPSHOT failed during execution of mojo: org.apache.maven.plugins:maven-ear-plugin:2.3.2:generate-application-xml

    Je soupçonne un problème de nom dans mon application.xml mais j'ai beau chercher je ne vois pas. Pourriez-vous indiquer le contenu de application.xml pour votre exemple ?

    Merci
  • Bonjour et merci pour votre retour

    Concernant votre premier point, c'est le premier projet m2eclipse + WTP que nous menons, donc je n'ai pas trop de recul là-dessus. Néanmoins, j'ai déjà beaucoup utilisé Seam avec m2eclipse sans problème. Les soucis de performance que l'on peut rencontrer avec m2eclipse sont liés aux fichiers de configuration eclipse qui entrent en conflit avec Maven. C'est la raison pour laquelle, il faut être très vigilant aux fichiers que l'on met sous subversion.

    Concernant votre second point... vous avez répondu vous même :-)

    Bonne journée
  • très bon article que je vais m'empresser de mettre en oeuvre. J'utilise déjà M2Eclipse avec WTP pour des war mais je n'avais jamais essayer de tester par moi même avec des EJB et des EAR car on m'avait dit que cela ne fonctionnait pas correctement.
  • aucean
    Bravo! Très bon article, clair et didactique.
    J'ai les idées un peu plus claires avec Maven maintenant.
    Mais petite question, cela change quoi d'avoir un projet maven parent?
    Le projet ear regroupe déjà tout nos projets lors de son build?
    Cela rajoute uniquement un avantage dans la gestion maven des projets c'est ca?
  • Le projet parent permet de regrouper le build de tous les sous-projets. Pour que ton EAR soit correctement construit il faut ne information de regroupement au niveau Maven. C'est ce à quoi sert ce projet parent à la base. En supplément, on peut y ajouter des paramètres partagés par tous les modules du projet (niveau du compilateur, version d'une collection de Jar, etc...)
blog comments powered by Disqus