-->

How to configure Maven to export depenencies in li

2019-08-28 10:04发布

问题:

I am trying to follow the AWS Lambda recommendations here, where they say:

Reduce the time it takes Lambda to unpack deployment packages authored in Java by putting your dependency .jar files in a separate /lib directory. This is faster than putting all your function’s code in a single jar with a large number of .class files.

I might be wrong, but the way I understand this, AWS recomments a zip archive structure like this:

my-code.jar
lib/my-dependency.jar

If this is what they mean, I can't achieve it, I tried to configure my Maven assembly plugin as:

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
    <id>distribution</id>
    <formats>
        <format>zip</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

   <fileSets>
       <fileSet>
           <directory>${project.basedir}\src\main\java</directory>
           <outputDirectory>\</outputDirectory>
       </fileSet>
   </fileSets>

    <dependencySets>
        <dependencySet>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

and what I get is:

lib/my-code.jar
lib/my-dependency.jar

So this leads me to 2 questions:

1 - Am I understanding AWS recommendations correctly? I am kinda new to Maven and the whole java build process.

2 - If I am understanding it correctly, then how can I achieve it?