Search code examples
maven-2m2eclipseartifacts

help for use maven artifacts


I'm learning Maven and I'd need a little help to get started. I use the m2eclipse plugin (Maven) and I would like to generate a project like Struts 2, Hibernate 3, MySQL. For now I just create a simple project with the archetype: maven-archetype-webapp

What are the dependencies I need to add?


Solution

  • For now I just create a simple project with the archetype: maven-archetype-webapp

    My suggestion would be to use the struts2-archetype-blank archetype instead to bootstrap your Struts 2 application. You can invoke it either from m2eclipse (via the wizards) or from the command line. For example from the command line:

    mvn archetype:generate -B \
                           -DgroupId=tutorial \
                           -DartifactId=tutorial \
                           -DarchetypeGroupId=org.apache.struts \
                           -DarchetypeArtifactId=struts2-archetype-blank \
                           -DarchetypeVersion=2.2.1
    

    The, add the required dependencies for Hibernate 3 and the MySQL JDBC driver. As often, there are several ways to do that:

    • manually (by adding <dependency> elements in the pom.xml)
    • using the m2eclipse wizards
      • via the dependencies tab of the pom editor
      • via a right-click on your project and then Maven > Add Dependencies
    • via the Eclipse quick-fix options

    The Adding Dependencies Using m2eclipse blog post has a screen cast demonstrating some of them.

    Whatever solution you'll choose, at the end, your pom.xml should at least declare the following deps:

    <project>
      <dependencies>
        ...
        <dependency>
          <groupId>org.apache.struts</groupId>
          <artifactId>struts2-core</artifactId>
          <version>2.2.1</version>
        </dependency>
        ...
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>3.3.2.GA</version>
        </dependency>
        <dependency>
          <groupId>javassist</groupId>
          <artifactId>javassist</artifactId>
          <version>3.9.0.GA</version>
        </dependency>
        ...
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>5.1.13</version>
        </dependency>
      </dependencies>
    
    </project>
    

    And If you want to use the latest version of Hibernate artifacts, you'll have to add the JBoss repository under the repositories element since they are not available in the maven central repository (sorry for making things more complicated but, well, that's how things are):

    <project>
      <dependencies>
        ...
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>3.5.5-Final</version>
        </dependency>
        ...
      <dependencies>
      ...
      <repositories>
        <repository>
          <id>repository.jboss.org-public</id>
          <name>JBoss repository</name>
          <url>https://repository.jboss.org/nexus/content/groups/public</url>
        </repository>
      </repositories>
      ...
    </project>