帮助使用Maven工件 [英] help for use maven artifacts

查看:189
本文介绍了帮助使用Maven工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Maven,并且需要一些帮助才能开始.我使用m2eclipse插件(Maven),并且想要生成一个项目,例如Struts 2,Hibernate 3,MySQL.现在,我只创建一个具有以下原型的简单项目: maven-archetype-webapp

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?

推荐答案

现在,我只创建一个具有原型的简单项目:maven-archetype-webapp

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

我的建议是使用struts2-archetype-blank原型来引导您的Struts 2应用程序.您可以从m2eclipse(通过向导)或从命令行调用它.例如,从命令行:

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

,添加Hibernate 3和MySQL JDBC驱动程序所需的依赖项.通常,有几种方法可以做到这一点:

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

    手动
  • (通过在pom.xml中添加<dependency>元素)
  • 使用m2eclipse向导
    • 通过pom编辑器的依赖项"标签
    • 通过
    • 右键单击您的项目,然后 Maven>添加依赖项
    • 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

      使用m2eclipse添加依赖项博客帖子的屏幕显示了其中的一些内容.

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

      无论选择哪种解决方案,最后,您的pom.xml至少应声明以下dep:

      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>
      

      如果您要使用最新版本的Hibernate工件,则必须在repositories元素下添加JBoss存储库,因为它们在maven中央存储库中不可用(抱歉使事情变得更复杂,但是,好吧,事情就是这样):

      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>
      

      这篇关于帮助使用Maven工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆