java 如何使用 Maven 获取所有必需的 Apache POI 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25305883/
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-11-02 07:48:57  来源:igfitidea点击:

How to get all of required Apache POI library using Maven?

javamavenjarapache-poi

提问by null

I have installed maven and I created a project using this command:

我已经安装了 maven 并使用以下命令创建了一个项目:

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

The result is there are 2 folder and 1 file created in my-app folder: src, target, and pom.xml.

结果是在 my-app 文件夹中创建了 2 个文件夹和 1 个文件:src、target 和 pom.xml。

Then I modify the pom.xml in order to get the all of required apache POI jars.

然后我修改 pom.xml 以获得所有必需的 apache POI jar。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.my-app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>my-app</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- This is what I added -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.10-FINAL</version>
    </dependency>
  </dependencies>
</project>

Then I run:

然后我运行:

mvn package

but no jars downloaded into the project folder although I got message "BUILD SUCCESS".

但是没有 jars 下载到项目文件夹中,尽管我收到消息“BUILD SUCCESS”。

回答by Mardoz

What you've done is correct. However, the poi jars won't download to your project folder but to your local Maven repository. This is exactly what Maven is supposed to do so that you don't have to manage many libraries/jars yourself and get all in a mess. If you do a search of your local Maven repository, you should find it there.

你所做的是正确的。但是,poi jar 不会下载到您的项目文件夹,而是下载到您的本地 Maven 存储库。这正是 Maven 应该做的事情,这样您就不必自己管理许多库/罐子而把一切都弄得一团糟。如果您搜索本地 Maven 存储库,您应该在那里找到它。

I also suggest you read up on how Maven uses external dependencies, this is all explained here: http://maven.apache.org/guides/getting-started/index.html#How_do_I_use_external_dependencies

我还建议您阅读有关 Maven 如何使用外部依赖项的信息,这里有全部解释:http: //maven.apache.org/guides/getting-started/index.html#How_do_I_use_external_dependencies

If you want to package up all of your dependent jars in to one big jar look here: How can I create an executable JAR with dependencies using Maven?

如果您想将所有依赖 jar 打包到一个大 jar 中,请查看此处: 如何使用 Maven 创建具有依赖项的可执行 JAR?

回答by Skizzo

Your project has a jar packaging type. Java not support nested jar and then maven package doesn't put any jar in your project . To do this you have to use Maven Assembly Pluginor use Spring-bootto make your uber jar

您的项目具有 jar 包装类型。Java 不支持嵌套 jar,然后 maven 包不会在您的项目中放置任何 jar。为此,您必须使用Maven Assembly Plugin或使用Spring-boot来制作您的 uber jar