Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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("Hello world");
    }
}

I have currently moved the .m2 repo (I'm using windows 10) via the following:

  1. Move .m2 repository to c:\
  2. Create a settings.xml via inteliJ containing the following:
<settings>
  <localRepository>c:/.m2/repository</localRepository>
</settings>

Even with the above settings / changes, I'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?

like image 231
SamP Avatar asked Aug 24 '20 16:08

SamP


1 Answers

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:

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

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:

<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>

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

  <dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-s3</artifactId>
  </dependency>
like image 145
Spike Williams Avatar answered Oct 23 '22 11:10

Spike Williams