Spring Cloud Function + AWS Adapter: Failed to discover main class in META-INF/MANIFEST.MF

237 Views Asked by At

I can't use spring boot starter parent in my project. And in the Spring Cloud Function github, the following is said:

Spring Cloud Function will try and locate a "main class" for you from the JAR file manifest, using the Start-Class attribute (which will be added for you by the Spring Boot tooling if you use the starter parent). If there is no Start-Class in your manifest you can use an environment variable or system property MAIN_CLASS when you deploy the function to AWS.

So I configured the maven-shaded-plugin as follows:

                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>aws</shadedClassifierName>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>mypackage.Main</mainClass>
                                <manifestEntries>
                                    <Start-Class>mypackage.Main</Start-Class>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>

With this, my MANIFEST ended up as following:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven 3.8.1
Built-By: dougl
Build-Jdk: 20.0.1
Main-Class: mypackage.Main
Start-Class: mypackage.Main

However, I'm getting this error when trying to execute the function:

22:24:06.739 [main] INFO org.springframework.cloud.function.utils.FunctionClassUtils - Searching for start class in manifest: file:/var/task/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven 3.8.1
Built-By: dougl
Build-Jdk: 20.0.1
Main-Class: mypackage.Main
Start-Class: mypackage.Main
Failed to discover main class. An attempt was made to discover main class as 'MAIN_CLASS' environment variable, system property as well as entry in META-INF/MANIFEST.MF (in that order).: java.lang.IllegalStateException
java.lang.IllegalStateException: Failed to discover main class. An attempt was made to discover main class as 'MAIN_CLASS' environment variable, system property as well as entry in META-INF/MANIFEST.MF (in that order).
    at org.springframework.cloud.function.utils.FunctionClassUtils.getStartClass(FunctionClassUtils.java:86)
    at org.springframework.cloud.function.utils.FunctionClassUtils.getStartClass(FunctionClassUtils.java:63)
    at org.springframework.cloud.function.adapter.aws.FunctionInvoker.start(FunctionInvoker.java:98)
    at org.springframework.cloud.function.adapter.aws.FunctionInvoker.<init>(FunctionInvoker.java:71)
    at org.springframework.cloud.function.adapter.aws.FunctionInvoker.<init>(FunctionInvoker.java:79)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Unknown Source)
    at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Failed to locate main class
    at org.springframework.util.Assert.notNull(Assert.java:201)
    at org.springframework.cloud.function.utils.FunctionClassUtils.getStartClass(FunctionClassUtils.java:82)
    ... 9 more

What I'm missing?

0

There are 0 best solutions below