Cannot create java function in azure function app

318 Views Asked by At

I want to create a very simple serverless function in Java for my web app. But I am having no success adding it to my function app.

Unfortunately most tutorials on the web and youtube seem to be out of date. The most recent videos show that there is a Function f(x) option in the function section. But at the moment this option seems to be not visible to me.

See screenshot :

enter image description here

As I think I understand you have to go to the “Create in Azure portal” button in functions tab

enter image description here

So I click on the button "Create in Azure Portal"

  • Select "Choose any editor + core tools"
  • Open the cloud shell
  • Run “func init” (I am not sure if this was correct. I think I needed to create a folder first. Now all these files are in the base directory)
  • Run “func new”. (Selecting on HTTP Request)
  • Then I run “func azure functionapp publish oliverwatkinsserverlessfunction”

I then get this error :

oliver [ ~/src ]$ func azure functionapp publish oliverwatkinsservlessfunction
Your Azure Function App has 'FUNCTIONS_WORKER_RUNTIME' set to 'java' while your local project is set to 'node'.
You can pass --force to update your Azure app with 'node' as a 'FUNCTIONS_WORKER_RUNTIME'

And I don't see any new function.

As I understand my function app is Java so I am not sure why it thinks it is a node application

1

There are 1 best solutions below

0
On

Your Azure Function App has 'FUNCTIONS_WORKER_RUNTIME' set to 'java' while your local project is set to 'node'. You can pass --force to update your Azure app with 'node' as a 'FUNCTIONS_WORKER_RUNTIME'

It looks like FUNCTIONS_WORKER_RUNTIME: java is not supported by core tools while creating the function using func init command. You can refer to the the ms docs and can create the function using following options.

enter image description here

While using func init command in cloud shell, Java is not available in the list to select.

enter image description here

I believe, you selected node. I chose custom, as Java is not there in the list then I got below error.

enter image description here

Here, I am using Maven commands to create Java function. You can also use visual studio code as given in ms docs.

  1. Used below command to create function in Maven.

    mvn archetype:generate "-DarchetypeGroupId=com.microsoft.azure" "-DarchetypeArtifactId=azure-functions-archetype" "-DjavaVersion=8"

enter image description here

enter image description here

  1. Run mvn clean install before executing the function locally.

enter image description here

  1. Executed the function locally using mvn azure-functions:run.

enter image description here

  1. Published using mvn azure-functions:deploy.

enter image description here

  1. After deployment, I can see the function in Azure and got the output as well.

enter image description here

enter image description here

You can choose your preferred development tool to create an azure function in Java.