【问题标题】:How do I get Maven to include a jar in my Eclipse Referenced Libraries?如何让 Maven 在我的 Eclipse 引用库中包含一个 jar?
【发布时间】:2011-02-03 20:07:14
【问题描述】:

我正在尝试获取一个现有的 Eclipse 项目并添加一个 pom.xml,以便我可以使用 Maven 进行自动构建。在项目中,我有一个不在 Maven 存储库中的引用库中的 jar 文件。为了让 Maven 识别 jar 文件,我需要做什么?

我在元素上摸索了一下,没有任何成功。

Windows XP、Eclipse 3.6.1、Maven 3.0.2

【问题讨论】:

    标签: eclipse maven


    【解决方案1】:

    在你的 pom.xml 中添加一个 <dependencies> 标签并在其中添加所有的 Jars 依赖项。它将在构建时下载。

    喜欢这个

    <project>
      ...
      <dependencies>
        <dependency>
          <groupId>group-a</groupId>
          <artifactId>artifact-a</artifactId>
          <version>2.1</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>group-a</groupId>
          <artifactId>artifact-b</artifactId>
          <version>1.0</version>
          <type>jar</type>
          <scope>runtime</scope>
        </dependency>
      </dependencies>
         ....
    </project>
    

    在这里查看更多http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

    对于公开可用的 Jars,您可以在此处搜索依赖项 http://mvnrepository.com/

    对于不公开的罐子,你可以在本地安装,通过

     mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
    

    see here

    我不确定如何从 Eclipse 中安装第三方 jar。一定有办法使用m2eclipse插件。

    【讨论】:

    • 非常感谢。我错过了如何在本地安装 jar。一旦我在本地安装它并更新我的 pom.xml 以匹配安装的内容,一切都对我有用。
    【解决方案2】:

    如果您使用的是 eclipse indigo,您还可以使用 m2e 将 jar 导入您的 maven 存储库。转到 file/import/maven/install 或将工件部署到 maven 存储库

    您只需要填写组和工件 ID

    【讨论】:

      猜你喜欢
      • 2012-12-22
      • 1970-01-01
      • 2011-12-20
      • 2013-03-20
      • 2011-10-23
      • 2012-11-17
      • 2011-12-07
      • 2012-06-06
      • 1970-01-01
      相关资源
      最近更新 更多