简体   繁体   English

在 Google Compute Engine VM 上执行 Java 文件

[英]Execute Java file on Google Compute Engine VM

I have been trying to import a Java project that I have developed on my own personal computer with IntelliJ to Google Compute Engine with no success.我一直在尝试将我在自己的个人计算机上使用 IntelliJ 开发的 Java 项目导入到 Google Compute Engine,但没有成功。 I have created a VM instance, but I do not know how to import my project and run it.我已经创建了一个 VM 实例,但我不知道如何导入我的项目并运行它。 I haven't found much information on this as most tutorials are about deploying web applications.我没有找到太多关于此的信息,因为大多数教程都是关于部署 Web 应用程序的。

My project is not a web application and no servers are involved, I just would like to take advantage of the computing power that Google offers to execute the program in less time.我的项目不是 Web 应用程序,也不涉及服务器,我只是想利用 Google 提供的计算能力在更短的时间内执行程序。

I would be grateful if you could provide me with some guidance on how to do that or point me to a relevant tutorial.如果您能为我提供有关如何执行此操作的指导或为我提供相关教程,我将不胜感激。

Assuming your Java application compiles to a JAR file, you can:假设您的 Java 应用程序编译为 JAR 文件,您可以:

  1. build your application locally on your workstation在您的工作站上本地构建您的应用程序
  2. create a Google Compute Engine VM instance创建一个 Google Compute Engine 虚拟机实例

    You can use either GCP Console to do this, or gcloud compute instances create .您可以使用GCP Console来执行此操作,也可以使用gcloud compute instances create

  3. upload the JAR file to the VM将 JAR 文件上传到 VM

    You can usegcloud compute scp to accomplish this.您可以使用gcloud compute scp来完成此操作。

  4. SSH to the VM SSH 连接到虚拟机

    You can do this via Google Cloud Shell , or viagcloud compute ssh .您可以通过Google Cloud Shellgcloud compute ssh

  5. run your program while logged in to the VM在登录到 VM 时运行您的程序

    Ensure that your software is written appropriately to take advantage of the multiple CPUs, GPUs, etc. the VM has to ensure it has maximum performance.确保正确编写您的软件以利用多个 CPU、GPU 等。VM 必须确保其具有最高性能。

    If this is a long-running process that you want to make sure doesn't accidentally get interrupted (eg, because your SSH session times out, or you close your browser window which as the Cloud Shell connection), consider using either nohup (easiest, especially for one-off runs) or running the command interactively in a detachable session such as screen or tmux (more involved).如果这是一个长时间运行的过程,您希望确保不会意外中断(例如,因为您的 SSH 会话超时,或者您关闭了作为 Cloud Shell 连接的浏览器窗口),请考虑使用nohup (最简单的,尤其是一次性运行)或在可分离的会话中以交互方式运行命令,例如screentmux (更多涉及)。

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

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