在Azure Function中从C#执行java.exe [英] Executing java.exe from C# in Azure Function

查看:88
本文介绍了在Azure Function中从C#执行java.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行Java以通过Azure函数运行JAR文件,但是似乎未定义java PATH变量或某些东西,因为Azure似乎找不到它.下面的代码:

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);
        }

即使我删除了proc.StartInfo.Arguments或告诉它使用java.exe而不是java,我仍然会遇到相同的错误,如下所示:

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

Azure函数不支持调用Java吗?

Is calling java not supported in Azure functions?

推荐答案

确定可以解决这个问题.到目前为止,最好的方法是完全限定java.exe的路径...

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

所以我改变了
proc.StartInfo.FileName = java.exe";

proc.StartInfo.FileName = "D:\\Program Files (x86)\\Java\\jdk1.8.0_73\\bin\\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";

您可以使用KUDU找出Java的完整路径,即 https://[yourFunctionName ] .scm.azurewebsites.net/

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

如果单击工具"->调试控制台",则可以浏览直到找到Java所在的位置.

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

请注意,对Java路径进行硬编码可能不是一个好主意,因此您应该使用应用程序设置.

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

编辑以下是我的最终项目与GitHub Repo的链接.该项目还有其他功能,但是您可以看到我在哪里调用Java来执行Batik JAR.
https://github.com/osuhomebase/SVG2PNG-AzureFunction

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

这篇关于在Azure Function中从C#执行java.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆