简体   繁体   English

如何在Azure上运行.jar文件

[英]How can I run a .jar file on azure

I have a complicated .jar file that I need to run on azure (C# ASP.NET). 我有一个复杂的.jar文件,需要在Azure(C#ASP.NET)上运行。 On my local system, I simply run java.exe and pass it the jar as an argument. 在我的本地系统上,我只运行java.exe并将jar作为参数传递给它。 I would like to do the same on the server, however, I don't know where java.exe is located. 我想在服务器上执行相同的操作,但是,我不知道java.exe的位置。

I have had a look at the environment variables and found many jdk and jre references, so I assume it is possible. 我查看了环境变量,发现了许多jdk和jre引用,因此我认为这是可能的。

I can not use ikvm, as the jar is too complex that it isn't running correctly. 我不能使用ikvm,因为jar太复杂了,无法正常运行。

So, as a summary: Where is the java.exe located on azure? 因此,作为总结:java.exe在azure上位于何处? And if it's not (and I can't do this), what else can I do? 如果不是(我不能这样做),我还能做什么?

EDIT: 编辑:

To clarify more: I am developing a web app using ASP.NET. 为了澄清更多:我正在使用ASP.NET开发一个Web应用程序。 I have a .jar file that I have to run, and on the local machine I run it using: 我有一个必须运行的.jar文件,并且在本地计算机上使用以下命令运行它:

 processStartInfo = new ProcessStartInfo("java");
 processStartInfo.Arguments = arguments;
 //more options
 Process process = new Process();
 process.StartInfo = processStartInfo;

 process.Start();
 process.WaitForExit();

Now I am publishing this website to Microsoft's azure services, and I would like to do the same thing. 现在,我正在将该网站发布到Microsoft的Azure服务上,我也想做同样的事情。 Except, running it as is tells me that the process can't be run (ie they don't understand what "java" is). 除此以外,按原样运行可告诉我该进程无法运行(即,他们不了解“ java”是什么)。 I want to find a way to be able to call java as a process. 我想找到一种方法,可以将java作为一个进程来调用。 Obviously, if I know the path to java.exe, I simply run the path as a command and I'll be done (ie it'll execute java). 显然,如果我知道java.exe的路径,则只需将路径作为命令运行即可完成操作(即它将执行Java)。 That's what I need help with. 这就是我需要帮助的地方。

As derpirscher mentions in the comment you haven't specified what type of Azure service you want to use, and you haven't specified the nature of your Java code (does it listen for incoming connections on some port? does it talk to any external services? etc.). 正如derpirscher在评论中提到的那样,您没有指定要使用的Azure服务类型,也没有指定Java代码的性质(它是否侦听某个端口上的传入连接?它是否与任何外部端口通信?服务?等)。 More info would help us give you a better answer. 更多信息将帮助我们为您提供更好的答案。

That said... one option to start with would be Azure Web Jobs, which allow you to upload and run (among other options) a Java .jar file: 就是说...一个开始的选项是Azure Web Jobs,它允许您上载和运行Java .jar文件(以及其他选项):

Azure Web Jobs overview Azure Web作业概述

As the info at that link indicates, you can run on-demand, continuously, or on a periodic schedule. 如该链接上的信息所示,您可以按需,连续或定期运行。 Some additional details found here: 在此处找到一些其他详细信息:

Executing Java Web Jobs on Azure 在Azure上执行Java Web作业

For more general information about both running Java code on Azure and also interacting with Azure services from within Java code, see here: 有关在Azure上运行Java代码以及在Java代码中与Azure服务进行交互的更多常规信息,请参见此处:

Azure Java Dev Center Azure Java开发中心

Specifically, here are some additional deployment options beyond Web Jobs: 具体来说,这是Web作业以外的一些其他部署选项:

Deploying Java code on Azure 在Azure上部署Java代码

Best of luck! 祝你好运!

EDIT based on your additional feedback: 根据您的其他反馈进行编辑:

So if I'm understanding, you want to invoke a Java .jar file by spawning a new process from an ASP.NET application when a user inputs a certain query, etc.? 因此,如果我了解的话,您想通过在用户输入特定查询等时从ASP.NET应用程序中产生一个新进程来调用Java .jar文件吗?

I can think of two potential options: 我可以想到两个潜在的选择:

  1. Host your ASP.NET application and the .jar on an Azure virtual machine that you customize with the correct version of Java, etc. This would allow you to configure Java how you like, on what path you want, etc. 将ASP.NET应用程序和.jar托管在使用正确版本的Java等自定义的Azure虚拟机上。这将允许您以所需的方式,所需的路径等来配置Java。

  2. Decouple the resources used to host your ASP.NET application from those used to invoke the Java code by (for instance) hosting your site as an Azure Web App and writing a message from there to an Azure storage queue each time the Java code should execute. 通过(例如)将您的站点作为Azure Web App托管,并在每次执行Java代码时将消息从其中写入Azure存储队列,将用于承载ASP.NET应用程序的资源与用于调用Java代码的资源分离开。 On the receiving side of the queue, you'd have an Azure Web Job configured to listen on that queue and execute your .jar file whenever a new message arrives. 在队列的接收方,您将配置一个Azure Web作业,以在该队列上侦听并在收到新消息时执行.jar文件。

Triggering a Web Job from an Azure Queue 从Azure队列触发Web作业

In general option 2 will be preferable from a scalability and pure design standpoint (allows you to separate the concerns of accepting queries vs. processing them, align costs most directly with actual resource consumption, etc.) but option 1 is perhaps easier from the perspective of someone unfamiliar with Azure or cloud architecture. 通常,从可伸缩性和纯设计的角度来看,选项2是更可取的(允许您将接受查询与处理问题分开,将成本与实际资源消耗最直接地对齐等),但是从角度来看,选项1可能更容易不熟悉Azure或云架构的人。

Just know that, depending on the nature of the processing you have to perform, number of expected concurrent users, etc. an acceptable VM-based solution may be more expensive than something similar to option 1 above. 只是知道,根据您必须执行的处理的性质,预期的并发用户数等,可接受的基于VM的解决方案可能比与上述选项1相似的解决方案更为昂贵。 Like so many things in cloud, its ultimately a time vs. expense tradeoff that you have to make here. 就像云中的许多事物一样,最终必须在时间与费用之间进行权衡。

Assumption that your application in C#/ASP.NET was running on Azure App Service like Azure WebApp. 假设您在C#/ ASP.NET中的应用程序正在Azure Web Service之类的Azure App Service上运行。 So you can access the Kudu console via the url https://<your-webapp-name>.scm.azurewebsites.net/DebugConsole , then you can command cd ..\\"Program Files (x86)"\\Java to move to the path of the collection of Java SDKs for different versions. 因此,您可以通过URL https://<your-webapp-name>.scm.azurewebsites.net/DebugConsole访问Kudu控制台,然后可以命令cd ..\\"Program Files (x86)"\\Java移至不同版本的Java SDK的集合路径。

Please try to use the absolute path for java.exe (like D:\\\\Program Files (x86)\\\\Java\\\\jdk<version\\\\bin\\\\java.exe> ) as the argument for the C# Class ProcessStartInfo . 请尝试将java.exe的绝对路径(例如D:\\\\Program Files (x86)\\\\Java\\\\jdk<version\\\\bin\\\\java.exe> )用作C#类ProcessStartInfo的参数。

However, I still recommend that you could try to deploy the application using Azure VM and run the app via configure the related environment variables on VM. 但是,我仍然建议您尝试使用Azure VM部署应用程序,并通过在VM上配置相关的环境变量来运行应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM