Maven错误 ‘206 文件名或扩展名过长’,在添加aws-java-sdk依赖后产生。

huangapple go评论92阅读模式
英文:

Maven error '206 the filename or extension is too long' after adding aws-java-sdk dependency

问题

目前我有一个Maven项目,在pom.xml文件中添加了以下依赖:https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk,但似乎我看到了以下异常:`CreateProcess error=206,文件名或扩展名太长`

当执行一个包含`public static void main`的类时:

```java
public class Connection_Test {
    public static void main(String[] args) {
        System.out.println("Hello world");
    }
}

我已经将.m2仓库移动到了.c盘下(我使用的是Windows 10),方法如下:

> 1. 将.m2仓库移动到c盘下
> 2. 通过IntelliJ创建一个settings.xml文件,其中包含以下内容:

<settings>
  <localRepository>c:/.m2/repository</localRepository>
</settings>

尽管进行了上述设置/更改,我仍然遇到相同的问题,不确定为什么在添加aws-java-sdk依赖后会遇到这个问题,有任何想法吗?


<details>
<summary>英文:</summary>

Currently I have a Maven Project, after adding the following dependency: https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk to the pom.xml file, I seem to be seeing the following exception: `CreateProcess error=206, The filename or extension is too long`

When executing a class which contains `public static void main`:

    public class Connection_Test {
        public static void main(String[] args) {
            System.out.println(&quot;Hello world&quot;);
        }
    }

I have currently moved the .m2 repo (I&#39;m using windows 10) via the following:

&gt; 1. Move .m2 repository to c:\
&gt; 2. Create a settings.xml via inteliJ containing the following:

    &lt;settings&gt;
      &lt;localRepository&gt;c:/.m2/repository&lt;/localRepository&gt;
    &lt;/settings&gt;

Even with the above settings / changes, I&#39;m still experiencing the same issue, not sure why after adding the aws-java-sdk dependency I seem to run into the issue, any ideas? 

</details>


# 答案1
**得分**: 3

问题似乎出在通过pom.xml文件导入aws java库的方式上。我看过一些文档和项目,其中有类似这样的操作:

```xml
<dependencies>
  <dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk</artifactId>
    <version>1.12.1</version>
  </dependency>
</dependencies>

然而,现在似乎有太多的子项目在aws-java-sdk下,列出它们所有会超出Windows 10上最大长度类路径的限制。

与其导入整个AWS SDK,最好只导入你需要的部分。这里有一些关于如何做到这一点的好文档1

要逐个导入SDK组件,首先需要在pom.xml文件的DependencyManagement部分启用aws-java-sdk-bom(材料清单)。像这样:

<dependencyManagement>   
  <dependencies>
     <dependency>
       <groupId>com.amazonaws</groupId>
       <artifactId>aws-java-sdk-bom</artifactId>
       <version>1.12.1</version>
       <type>pom</type>
       <scope>import</scope>
     </dependency>   
  </dependencies> 
</dependencyManagement>

然后,要引入S3,你必须将aws-java-sdk-s3列为它自己的依赖项。

<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-java-sdk-s3</artifactId>
</dependency>
英文:

The problem appears to be in the way the aws java libraries are imported through the pom.xml file. I've seen documentation and projects that do something like this:

&lt;dependencies&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
    &lt;artifactId&gt;aws-java-sdk&lt;/artifactId&gt;
    &lt;version&gt;1.12.1&lt;/version&gt;
  &lt;/dependency&gt;
&lt;/dependencies&gt;

However, it appears that there are now so many sub-projects under aws-java-sdk that listing them all breaks the maximum length classpath on Windows 10.

Instead of importing the entire AWS SDK, its better to only import the part that you need. There is some good documentation on that here.

To import SDK components one at a time, you need to first enable the aws-java-sdk-bom (Bill of Materials) in the pom.xml file's DependencyManagement section. Like so:

&lt;dependencyManagement&gt;   
  &lt;dependencies&gt;
     &lt;dependency&gt;
       &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
       &lt;artifactId&gt;aws-java-sdk-bom&lt;/artifactId&gt;
       &lt;version&gt;1.12.1&lt;/version&gt;
       &lt;type&gt;pom&lt;/type&gt;
       &lt;scope&gt;import&lt;/scope&gt;
     &lt;/dependency&gt;   
  &lt;/dependencies&gt; 
&lt;/dependencyManagement&gt;

And then, to bring in S3, you have to have aws-java-sdk-s3 listed as its own dependency.

  &lt;dependency&gt;
    &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
    &lt;artifactId&gt;aws-java-sdk-s3&lt;/artifactId&gt;
  &lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年8月25日 00:02:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63564630.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定