Is vagrant useful for java/javaee developers? [clo

2019-03-17 12:59发布

问题:

When working with java/javaee usual development environment setup is to have everything locally (jdk installation, database, appserver etc). I know a lot of people in ruby/js world use virtual machines for development (mainly with vagrant).

I wonder if there is an efficient way to set up similar env for java/javaee. I suspect that I can easily install database server and application server together with jdk version on such virtual machine, but what about regular development? I still need to have jdk installed locally, right? (I need my IDE to work properly) I need maven to build my project, so that I need full maven local repo. And then I need to deploy my app on virtual machine's app server.

I can see no real advantage here (still having pieces of environment on both machines). Do you have any experience with that and can share with me?

回答1:

Vagrant is basically a tool for setting up a VirtualBox virtual machine. It brings to the table the ability to quickly provision a VM and the ability to pass the provisioning recipe to others.

This is really useful in the Ruby/JS community because they don't have a compile step. The way we use it is the code stays on my local machine and all the runtime is done on the VM. If I make a change on my local computer the running program on the VM instantly picks up the change and the runtime is modified just as if the code was only on the VM. I literally don't even have to have Ruby/JS installed on my computer.

In the Java/.Net world you have a compile step so as you say you need Java and all the jars you need to compile against on your machine. This lessens some of the usefulness of the setup.

On the other hand you usually have databases, message queues, containers, etc. that you are working with and on a team it may be a pain to shoot an email and say update your db to this version and load the new sample data. In Vagrant only one person needs to make the updates and they can then tell you to grab the new VM and you do not have to do any of the upgrade steps yourself.

So it is still useful in a compiled language but it is less useful than in a scripting language.



回答2:

It's not entirely clear what specifically you're looking for in terms of an answer.

IMO the value of virtual machines isn't so much for the development environment, but the runtime environment. Things like messaging/queuing, servers, databases, cloud servers (e.g., Swift), etc.

This is language-independent. For example, we have virtual machines (not Vagrant-based) that include Hadoop/HDFS/HBase, Swift, RabbitMQ, and a variety of containers.

We might deploy to those machines, but the dev tools are run locally. IMO there would be little reason to develop on the virtual machine, although there's no reason you couldn't, especially if you're comfortable with Vim/Emacs/etc.

I know there's a Tomcat container for Vagrant, although I haven't used it.