Vagrant For Java: Should we compile on the host or the VM?

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

Much of the time Vagrant is advertised for development with PHP, Ruby, Node, etc. For these languages, code is edited on the host and run on the VM. There is no compilation step, so the “edit here / run there” paradigm works very well.

However, it seems to be not very well defined exactly how a Java IDE and the compile/deploy process work with a Vagrant VM. One could make an argument for compiling on the VM or for compiling on the host machine, or even from running the IDE directly inside the VM. Other answers on Stackoverflow have implied that Vagrant is less useful for compiled languages because of the extra compile step, but let’s give it some thought and examine the pros and cons.

Some considerations:

Why have IDE or compile on the VM

  • If compiling on host, Java is one more piece of software to install, and it introduces a complication if you want to use different versions of Java for different projects
  • II compiling on host, the Java version on host must be manually kept up to date with that on the project’s VM. The corresponding Java version on the host might be unavailable (say, on a Mac where historically Java releases have lagged behind those for other platforms)
  • Tighter integration between the compilation environment and the IDE allow you to use shortcuts to compile and run the application
  • We can connect the debugger for Java (non-web) applications without remote debugging (one click run/debug)
  • If everything is on the VM including tools, this provides an instant development environment so new developers can get up and running very quickly

Why have IDE or compile on the host

  • Faster compile times
  • Ensures compile and run are done with the same JDK
  • Better UI performance (X forwarding and VNC are too slow for daily development)

What are your thoughts: Is it better to run the IDE from inside the VM or the host? Should Java be compiled from inside the VM or the host?

Advertisements

Leave a comment

Filed under Software Engineering

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s