I am trying to execute Spring Azure Functions from IntelliJ.
The example I am using is here:
When I click on the Run Azure Function Button on IntelliJ:
The application starts up normally, but fails when I try to hit any endpoint:
http://localhost:7071/api/scf
With the error:
[2023-09-13T12:59:34.868Z] System.Private.CoreLib: Exception while executing function: Functions.bean. System.Private.CoreLib: Result: Failure
Exception: IllegalArgumentException: Failed to locate main class
Stack: java.lang.IllegalStateException: Failed to initialize
This happens ONLY when running from IntelliJ. It does not happen when I use the command:
mvn azure-functions:run
Possible reasons for the error:
The app is unable to locate the "start class" defined in the pom.xml
when using the plugin:
<start-class>com.example.azure.di.httptriggerdemo.HttpTriggerDemoApplication</start-class>
You can see by the difference in the traces when the application is run from plugin vs Maven:
Plugin version: (Looks in the wrong places)
[2023-09-13T12:59:34.390Z] Executing 'Functions.bean' (Reason='This function was programmatically called via the host APIs.', Id=e363957c-09eb-4602-b76b-97a419b8f938)
[2023-09-13T12:59:34.698Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.699Z] INFO: Searching for start class in manifest: jar:file:/C:/Program%20Files/Microsoft/Azure%20Functions%20Core%20Tools/workers/java/azure-functions-java-worker.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.700Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.700Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-cloud-function-context-4.1.0-20230911.141441-157.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.702Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.702Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-cloud-function-core-4.1.0-20230911.141334-157.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.704Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.704Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-core-6.1.0-M4.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.706Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.707Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/azure-httptrigger-demo.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.709Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.709Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-messaging-6.1.0-M4.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.711Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.711Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/micrometer-observation-1.12.0-M2.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.713Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.713Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-cloud-function-adapter-azure-4.1.0-20230911.141719-144.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.714Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.714Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-context-6.1.0-M4.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.715Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.715Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-boot-3.2.0-M2.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.716Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.716Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-aop-6.1.0-M4.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.720Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.720Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/jackson-annotations-2.15.2.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.722Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.723Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/reactive-streams-1.0.4.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.724Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.724Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/jakarta.annotation-api-2.1.1.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.726Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.726Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-expression-6.1.0-M4.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.729Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.729Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/snakeyaml-2.1.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.732Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.732Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/reactor-core-3.6.0-M2.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.734Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.734Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/micrometer-commons-1.12.0-M2.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.735Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.736Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/typetools-0.6.2.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.737Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.738Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-boot-autoconfigure-3.2.0-M2.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.740Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.740Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/jackson-core-2.15.2.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.740Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.743Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-jcl-6.1.0-M4.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.743Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.743Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-boot-starter-3.2.0-M2.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.762Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.763Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/azure-functions-java-library-3.0.0.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.764Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.764Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/jackson-databind-2.15.2.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.766Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.766Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/spring-beans-6.1.0-M4.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.780Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.781Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/AppData/Local/Temp/azure-functions6066515897205809182/lib/azure-functions-java-spi-1.0.0.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.782Z] Sep 13, 2023 6:29:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T12:59:34.782Z] INFO: Searching for start class in manifest: jar:file:/C:/Program%20Files/Microsoft/Azure%20Functions%20Core%20Tools/workers/java/annotationLib/azure-functions-java-library-2.0.1-SNAPSHOT.jar!/META-INF/MANIFEST.MF
[2023-09-13T12:59:34.867Z] Executed 'Functions.bean' (Failed, Id=e363957c-09eb-4602-b76b-97a419b8f938, Duration=536ms)
[2023-09-13T12:59:34.868Z] System.Private.CoreLib: Exception while executing function: Functions.bean. System.Private.CoreLib: Result: Failure
Exception: IllegalArgumentException: Failed to locate main class
Stack: java.lang.IllegalStateException: Failed to initialize
Maven Version (Looks in the correct place and finds the start class):
[2023-09-13T13:01:33.990Z] Executing 'Functions.bean' (Reason='This function was programmatically called via the host APIs.', Id=532d5eb5-6323-4de9-b294-27911cb6fdea)
[2023-09-13T13:01:34.153Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.154Z] INFO: Searching for start class in manifest: jar:file:/C:/Program%20Files/Microsoft/Azure%20Functions%20Core%20Tools/workers/java/azure-functions-java-worker.jar!/META-INF/MANIFEST.MF
[2023-09-13T13:01:34.158Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.159Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/IdeaProjects/spring-cloud-function/spring-cloud-f
unction-samples/function-sample-azure-http-trigger/target/azure-functions/spring-cloud-function-samples/lib/reactive-streams-1.0.4.jar!/META-INF/MANIFEST.MF
[2023-09-13T13:01:34.164Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.165Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/IdeaProjects/spring-cloud-function/spring-cloud-f
unction-samples/function-sample-azure-http-trigger/target/azure-functions/spring-cloud-function-samples/lib/spring-boot-3.2.0-M2.jar!/META-INF/MANIFEST.MF
[2023-09-13T13:01:34.171Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.172Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/IdeaProjects/spring-cloud-function/spring-cloud-f
unction-samples/function-sample-azure-http-trigger/target/azure-functions/spring-cloud-function-samples/lib/azure-functions-java-spi-1.0.0.jar!/META-INF/MANIFEST.MF
[2023-09-13T13:01:34.173Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.174Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/IdeaProjects/spring-cloud-function/spring-cloud-f
unction-samples/function-sample-azure-http-trigger/target/azure-functions/spring-cloud-function-samples/lib/micrometer-commons-1.12.0-M2.jar!/META-INF/MANIFEST.MF
[2023-09-13T13:01:34.180Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.181Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/IdeaProjects/spring-cloud-function/spring-cloud-f
unction-samples/function-sample-azure-http-trigger/target/azure-functions/spring-cloud-function-samples/lib/reactor-core-3.6.0-M2.jar!/META-INF/MANIFEST.MF
[2023-09-13T13:01:34.183Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.185Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/IdeaProjects/spring-cloud-function/spring-cloud-f
unction-samples/function-sample-azure-http-trigger/target/azure-functions/spring-cloud-function-samples/lib/azure-functions-java-library-3.0.0.jar!/META-INF/MANIFEST.MF
[2023-09-13T13:01:34.186Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.187Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/IdeaProjects/spring-cloud-function/spring-cloud-f
unction-samples/function-sample-azure-http-trigger/target/azure-functions/spring-cloud-function-samples/lib/spring-core-6.1.0-M4.jar!/META-INF/MANIFEST.MF
[2023-09-13T13:01:34.190Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.191Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/IdeaProjects/spring-cloud-function/spring-cloud-f
unction-samples/function-sample-azure-http-trigger/target/azure-functions/spring-cloud-function-samples/lib/spring-aop-6.1.0-M4.jar!/META-INF/MANIFEST.MF
[2023-09-13T13:01:34.192Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.195Z] INFO: Searching for start class in manifest: jar:file:/C:/Users/ng.newbie/IdeaProjects/spring-cloud-function/spring-cloud-f
unction-samples/function-sample-azure-http-trigger/target/azure-functions/spring-cloud-function-samples/azure-httptrigger-demo-0.0.1-SNAPSHOT.jar!/META-INF/MANIFEST.MF
[2023-09-13T13:01:34.196Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.197Z] INFO: Loaded Start Class: class com.example.azure.di.httptriggerdemo.HttpTriggerDemoApplication
[2023-09-13T13:01:34.198Z] Sep 13, 2023 6:31:34 PM org.springframework.cloud.function.utils.FunctionClassUtils getStartClass
[2023-09-13T13:01:34.198Z] INFO: Main class: class com.example.azure.di.httptriggerdemo.
I believe the reason why this is happening is because of the thin-layout plugin used to change the layout in the beginning:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>${spring-boot-thin-layout.version}</version>
</dependency>
</dependencies>
</plugin>
As per @tzolov's comment's if you declare
MAIN_CLASS
as an environment variable it works.
If you want to add into a local run then add it in the "Run Configurations":
As the Main-Class Configuration documentation suggests, one ca use the MAIN_CLASS
environment variable to explicitly set the main class in the IDE's run configuration.