Vilerant for Java项目:您应该在VM中还是在主机上编译? [英] Vagrant for a Java project: should you compile in the VM or on the host?

查看:146
本文介绍了Vilerant for Java项目:您应该在VM中还是在主机上编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个问题:当将Vagrant用于Java项目(或任何编译语言项目)时,您应该在VM中还是在主机上编译?此外,您是否希望您的IDE和所有开发工具也可以在VM内部或主机上运行?

Here’s the question: When using Vagrant for a Java project (or any compiled language project for that matter), should you compile in the VM or on the host? Also, would you want your IDE and all your development tools to be run from inside the VM as well, or on the host?

它似乎是没有很好地定义 Java IDE和编译/部署过程的确切工作方式使用Vagrant VM。一般来说,我的印象是代码在主机上编辑,并在VM上运行,这对非编译语言非常有用。 Stackoverflow上的其他答案暗示Vagrant对编译语言不太有用因为额外的编译步骤,但我仍然想看看可以做些什么。

It seems to be not very well defined exactly how a Java IDE and the compile/deploy process work with a Vagrant VM. Generally my impression is that code is edited on the host, and run on the VM, which works great for non-compiled languages. Other answers on Stackoverflow have implied that Vagrant is less useful for compiled languages because of the extra compile step, but I still want to see what can be done.

我已经考虑过的一些事情:

Some things I’ve thought through already:

为什么要在VM上编译


  • 如果在主机上编译,则java是要安装的另一个软件

  • 如果在主机上进行编译,主机上的java版本必须手动保持与VM上的版本相同

  • 主机上相应的java版本可能不可用(例如,在Mac上)

为什么VM上有IDE

Why have IDE on the VM


  • 环境与IDE之间更紧密的集成,可以使用快捷方式运行应用程序

  • 无需远程调试即可连接java应用程序的调试器(一步运行/调试)

为什么编译在主机上


  • 更快的编译时间

  • 想让VM保持接近生产的样子尽可能

为什么主机上有IDE

Why have IDE on the host


  • 在主机上编辑代码并在VM上运行它的流浪惯例

  • 更好的UI性能(X转发和VNC很慢)

您有什么想法:我应该从VM或主机内部运行IDE吗?我应该从VM或主机内部编译吗?

What are your thoughts: should I run my IDE from inside the VM or the host? Should I compile from inside the VM or the host?

推荐答案

经过深思熟虑和实验,我决定在哪里使用Vagrant以及它如何与Java开发工作流程集成。

After much thought and experimentation, I've decided on where to use Vagrant and how it integrates with the Java development workflow.

对于JavaEE /已部署的应用程序,配置Web服务器和数据库服务器绝对是具有足够复杂性的东西。保证使用Vagrant。有了两台服务器和无数种配置方式,配置很容易从一个开发人员转到另一个开发人员,导致我的机器上的工作综合症。对于这种软件,最好在主机上编辑和编译代码,并部署到模仿生产环境的Vagrant VM。 Web服务器的部署文件夹甚至可以符号链接到主机上的编译目标,从而无需手动重新部署。因此,Vagrant可能是开发生命周期的重要组成部分,但是从主机进行代码/编译/部署以及在使用Java的VM上运行的周期时间将长于主机上的代码的周期时间并在VM上运行我们看到PHP / Ruby / Node / etc。

For JavaEE / deployed applications, configuring a web server and a database server are definitely things that have "enough" complexity to warrant the use of Vagrant. With two servers and the myriad ways to configure them, it's easy for configuration to get out of sync from one developer to another, bringing about the "works on my machine" syndrome. For this kind of software, it would work best to edit and compile the code on the host, and deploy to a Vagrant VM that mimics your production environment. The deployment folder for the web server could even be symlinked to a compile target on the host, removing the need to manually redeploy. So Vagrant could be an important part of your development lifecycle, but the cycle time for code/compile/deploy from the host and run on the VM with Java would be longer than the cycle time for code on the host and run on the VM that we see with PHP/Ruby/Node/etc.

对于独立的Java应用程序(如库或桌面应用程序),故事有所改变。在这种情况下,最有意义的是在主机上编辑,编译和运行,完全避免使用Vagrant。如果您正在使用其中一个大型Java IDE(Eclipse,Netbeans,IntelliJ ...),那么您已经在计算机上安装了Java。在这一点上,与使用Vagrant的开销相比,几乎没有什么优势,只会在开发过程中增加额外的复杂性。这是因为当您能够使用IDE编辑Java时,您无论如何都可以在主机上运行所有内容。一个问题是项目所需的Java版本可能与主机上运行IDE的版本不匹配。总的来说(希望如此)这不是一个问题;在撰写本文时,JDK6已经过时,而JDK8尚未发布(猜测它离开了我们的地方)。但是如果你确实需要运行多个版本,那么你应该能够根据需要在主机上设置JAVA_HOME。虽然这确实引入了额外的复杂性,但它比维护Vagrant运行时只是为了使用不同版本的Java的项目更复杂。

For standalone Java applications (like libraries or desktop applications) the story changes a bit. In this case it makes the most sense to edit, compile, and run on the host machine, eschewing the use of Vagrant altogether. If you're using one of the big Java IDE's (Eclipse, Netbeans, IntelliJ...), you already have Java installed on the machine. At that point there is very little advantage compared to the overhead of using Vagrant, and only serves to put an extra layer of complexity in your development process. This is because by the time you are able to edit Java with an IDE you are able to run everything on the host anyway. One issue is that the version of Java required for the project may not match the version running the IDE on the host. In general (hopefully) this is not too much of a problem; as of this writing JDK6 is end-of-lifed and JDK8 is not yet released (guess where that leaves us). But if you did need to run multiple versions, you should be able to set JAVA_HOME on the host as needed. Though this does introduce extra complexity, it is less complexity than maintaining a Vagrant runtime just to work with projects using different versions of Java.

有趣的问题是如何处理无容器Web应用程序。 Web服务器(在这种情况下是应用程序内部)是否应该像在外部Web服务器中那样在VM内部运行?或者像我们为独立应用程序所做的那样在主机上运行?对于无容器Web应用程序,不需要担心外部Web服务器,但仍有可能存在数据库。在这种情况下,我们可以采取混合方法。运行无容器Web应用程序与运行独立应用程序基本相同,因此在主机上编译和运行代码会很有效。但是在涉及数据库的情况下,仍然存在足够的复杂性和配置,使数据库服务器位于其自己的Vagrant VM上是有意义的。

The interesting question is what to do with containerless web applications. Should the web server (in this case internal to the application) be run inside the VM as we did for the external web server? Or run on the host as we did for the standalone application? For containerless web applications, there is no external web server to worry about, but there is still likely a database. In this situation we can take a hybrid approach. Running a containerless web app is essentially the same as running a standalone application, so it would be effective to compile and run your code on the host machine. But with a database involved there is still enough complexity and configuration there that it makes sense to have the database server be on its own Vagrant VM.

希望这能为Java开发人员提供帮助我们对Vagrant有关如何使用它的一些背景感兴趣。

Hopefully this gives Java developers who are interested in Vagrant some context about how to use it.

这篇关于Vilerant for Java项目:您应该在VM中还是在主机上编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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