【问题标题】:does installing third party jars in local repository needs pom file configuration?在本地存储库中安装第三方 jar 需要 pom 文件配置吗?
【发布时间】:2014-06-18 05:59:47
【问题描述】:

我制作了一些 jar 文件(在 CMD 中使用 java 和 jar 命令),但是当我尝试通过以下命令将它们安装在本地目录中时(将其用作本地 maven 存储库):

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

但是 maven 给了我以下错误:

The goal you specified requires a project to execute but there is no POM in this directory

这意味着这个命令需要一个pom文件但是哪个pom文件(我是否需要再次用maven重新打包我的代码!)

【问题讨论】:

  • @prabugp 如果您只想安装 jar,那么,一个空的 pom 就足够了吗?无论如何,我不明白为什么只需要安装一个 3rd 方工件。
  • @perencia 你是对的。这不是必需的。我被错误信息误导了。 OP,请看看你是否被这个咬了:stackoverflow.com/a/11199865/2231632?我只是在一个非项目目录中执行了这个,它对我有用。还有一个错字:它是 -DartifcatId 而 - 不见了。
  • DartifactId 之前缺少的连字符可能是问题所在 - maven 试图将 Dartifact.... 视为目标名称。

标签: java maven


【解决方案1】:

我建议不要用Java构建jar,而是使用maven来构建和安装它。

1) 设置一个新的简单 Maven 项目

mvn archetype:create -DgroupId=yourProject -DartifactId=yourProjectsArtifactID -DarchetypeArtifactId=maven-archetype-quickstart

(http://maven.apache.org/plugins-archives/maven-archetype-plugin-1.0-alpha-7/examples/simple.html)

2) 将 jar 的 Java 源代码放入生成的文件夹中: ...\yourProjectsArtifactID\src\main\java

3) 如果需要,请声明代码的依赖项 在将其编译为 ...\yourProjectsArtifactID 中的 POM.xml 时,它应该包含在类路径中。您可以通过在文本编辑器中打开它并复制您希望在类路径中拥有的每个 jar 的现有条目来实现。将 scope 标记中的值更改为 compile 或将其删除。

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

4) 编译并安装你的jar

运行

mvn clean install

在 pom.xml 所在的文件夹中:“...\yourProjectsArtifactID”:

【讨论】:

    【解决方案2】:

    首先转到您的 maven conf/settings.xml 并定义您的本地 repo 位置:

    Repository>E:/repo2/</localRepository>
    

    然后转到 CMD 并输入:

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

    注意:因为在这种情况下您没有任何 pom。你应该定义所有必要的参数(groupid、artifactid、packaging 和 version),否则你会得到一个异常。

    注意:如果在您的字符串中,包含空格,您需要用双引号 ("") 将其括起来。

    另请注意,您可以通过参数 (-DlocalRepositoryPath) 明确告知本地 repo 的位置。

    如果上述配置不起作用,您可以将所有配置信息保存在 pom 文件中,并像下面这样明确引用它:

    mvn install:install-file -Dfile=<path-to-file>  -DpomFile=<path to pom file>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-29
      • 2012-03-15
      • 2014-07-07
      • 2015-05-15
      • 2015-01-23
      • 2015-05-13
      • 2014-12-03
      • 1970-01-01
      相关资源
      最近更新 更多