Java - 在 pom.xml 中添加 jar 依赖

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27009549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 03:39:25  来源:igfitidea点击:

Java - Adding jar dependency in pom.xml

javamavenjarrestful-architecture

提问by Fahad Mullaji

I have never built my java applications by maven. But when i am trying to do that it's giving me error. I have created JAR file from other java application just by exporting as JAR from that application. Now i want to add this JAR in my maven application. I don't really how to do that.

我从来没有用 Maven 构建过我的 Java 应用程序。但是当我尝试这样做时,它给了我错误。我只是通过从该应用程序导出为 JAR 来从其他 Java 应用程序创建 JAR 文件。现在我想在我的 Maven 应用程序中添加这个 JAR。我真的不知道该怎么做。

this is how i have added in pom.xml. But i don't really know what should be it's artifact id. Seriously what is artifact id?

这就是我在 pom.xml 中添加的方式。但我真的不知道它的工件 ID 应该是什么。说真的,什么是工件 ID?

<dependency>
        <groupId>ProjectZen</groupId>
        <artifactId>community</artifactId>
        <scope>system</scope>
        <version>1</version>
        <systemPath>${basedir}\libs\ProjectZen.jar</systemPath>
    </dependency>

I am getting below error

我得到以下错误

Missing artifact ProjectZen:community:jar:1

Thanks Fahad Mullaji

感谢法赫德·穆拉吉

回答by Jigar Joshi

change

改变

<systemPath>${basedir}\libs\ProjectZen.jar</systemPath>

to

<systemPath>${basedir}/libs/ProjectZen.jar</systemPath>

or install it in local maven cache

将其安装在本地 Maven 缓存中

回答by sar

If it is custom jar you need to do following things Open cmd and type following command

如果是自定义 jar,则需要执行以下操作 打开 cmd 并键入以下命令

  mvn install:install-file  -Dfile=path-to-your-artifact-jar \
                      -DgroupId=ProjectZen
                      -DartifactId=community
                      -Dversion=1
                      -Dpackaging=jar
                      -DgeneratePom=true

Now, the “ProjectZen” jar is copied to your Maven local repository.

现在,“ProjectZen”jar 已复制到您的 Maven 本地存储库。

In pom.xml

在 pom.xml 中

  <dependency>
    <groupId>ProjectZen</groupId>
    <artifactId>community</artifactId>
    <scope>system</scope>
    <version>1</version>
    <systemPath>${basedir}\libs\ProjectZen.jar</systemPath>
</dependency>

now the “ProjectZen” jar is able to retrieve from your Maven local repository.

现在“ProjectZen”jar 可以从您的 Maven 本地存储库中检索。

回答by Ayush Gupta

you should give the format as below. and the slashes used in are incorrect I suppose. Check the dependency in this format. ...

你应该给出如下格式。我想其中使用的斜杠是不正确的。检查这种格式的依赖关系。...

<profiles>
<profile>
  <id>default-tools.jar</id>
  <activation>
    <property>
      <name>java.vendor</name>
      <value>Sun Microsystems Inc.</value>
    </property>
  </activation>
  <dependencies>
    <dependency>
      <groupId>com.sun</groupId>
      <artifactId>tools</artifactId>
      <version>1.4.2</version>
      <scope>system</scope>
      <systemPath>${java.home}/../lib/tools.jar</systemPath>
    </dependency>
  </dependencies>
</profile>

Reference

参考

...

...