Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up a java/j2ee development environment with: Eclipse, Tomcat and Vagrant

I would like to use Vagrant (See here) together with VirtualBox in order to set up a java development environment to work on webapps (*.war archives for that matter).

I would have Eclipse installed on the host and MySql on the guest (that's pretty straightforward so far) but I want to have Tomcat run on the guest too and that where it is getting more difficult.

My questions are:

  • What files/folders am I supposed to share? (not the whole eclipse workspace I suppose)
  • Am I better off using a exploded or a normal war archive?
  • How do I configure Eclipse (which lives on the host) to see the remote Tomcat (the one that lives on the guest).

Is all of this really feasible with Vagrant?

EDIT 1: Here is a screen capture of my Eclipse's Tomcat:

screen capture of my tomcat

like image 220
balteo Avatar asked Oct 03 '22 13:10

balteo


1 Answers

What files/folders am I supposed to share? (not the whole eclipse workspace I suppose)

IMHO, share the project you are working on is enough. This way you may have one VM for each project.

You have two options to generate the war:

  1. build on host;
  2. build on VM (preferred).

If you choose Option 1: Since your project folder is shared with VM, you can copy the war to $CATALINA_HOME/webapps once you ssh to VM.

I would suggest Option 2 because you could keep the build environment as close to your production environment as possible.

Am I better off using a exploded or a normal war archive?

I would use normal war archive, but there's not much difference here.

How do I configure Eclipse (which lives on the host) to see the remote Tomcat (the one that lives on the guest).

You have two options here:

  1. Setup port forwarding in vagrantfile;
  2. Setup a private network, which is my preferred way since you don't have to forward every single port manually if more than one services running on VM need to be accessed from host machine.

How to configure Host-Only Networks

config.vm.network "hostonly", "192.168.0.0"

Have this line in your Vagrantfile will instruct vagrant to create a private network that has a static IP address: 192.168.0.0

The IP address of the host is always the same IP address but with the final octet as a 1. In the preceding example, the host machine would have the IP address 192.168.0.1.

like image 96
Mingyu Avatar answered Oct 07 '22 22:10

Mingyu