2

I'm trying to execute java to run a JAR file from an Azure function, but it seems like the java PATH variable isn't defined or something because Azure can't seem to find it. Code below:

 Process proc = new Process();
        try
        {
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.FileName = "java.exe";
            proc.StartInfo.Arguments = "-jar file path and some more arguments";
            proc.Start();
            proc.WaitForExit();
            if (proc.HasExited)
                log.Info(proc.StandardOutput.ReadToEnd());

            log.Info("Java Success!");
        }
        catch (Exception e)
        {
            log.Info("Java Fail");
            log.Info(e.Message);
        }

Even if I remove the proc.StartInfo.Arguments or tell it to use java.exe instead of java I still get the same error, below:

[Info] The system cannot find the file specified

Is calling java not supported in Azure functions?

1

2 Answers 2

4

OK figured this out. So far, the best way is to fully qualify the path to java.exe...

so I changed
proc.StartInfo.FileName = java.exe";
to
proc.StartInfo.FileName = "D:\\Program Files (x86)\\Java\\jdk1.8.0_73\\bin\\java.exe";

You can figure out the full path to Java using KUDU, which is https://[yourFunctionName].scm.azurewebsites.net/

If you click on Tools->DebugConsole, you can browse until you find where Java is located.

Note hard coding the path to Java is probably a bad idea so you should probably use application settings.

Edit Below is a link to a GitHub Repo with my final project. The project does some other stuff, but you can see where I call Java to execute the Batik JAR.
https://github.com/osuhomebase/SVG2PNG-AzureFunction

Sign up to request clarification or add additional context in comments.

2 Comments

IMHO the proper way to do this is: proc.StartInfo.FileName = Environment.ExpandEnvironmentVariables(Path.Combine("%JAVA_HOME%", "bin", "java.exe")); You should always use environment variable (if available) and not the absolute path of the binary :).
Hehe, I was looking at your code and then was questioning myself okay okay but how does that work, is java installed on each host then came here. Are you still using this piece of code?
0

As of September 2022,

proc.StartInfo.FileName = java.exe";

Worked fine for me. It appears the Azure Function Environment has the JDK installed and the JAVA PATH variable set.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.