views:

240

answers:

3

I have a pretty monstrous Java app in development here. As of now, it's only ever been deployed on my locally installed Tomcat/MySQL setup.

For completeness, the app is an online game server written using Spring, Hibernate with MySQL currently on the backend.

Now, I can easily package up the WAR and get that on the remote server.. The problem is the database. Right now it's generated with an ANT script that uses Hibernate (specifically, the HBM2DDL Ant task) to generate the schema, and then populates the db with a combination of static SQL and a couple of ant-based parsers that read from other data (XML mostly). After that, I have a fully created DB populated with the game servers "starting" data set.

The issue is being a bit green in Java I have no idea what the right way to deploy this is.

Should I:

  1. Export the SQL from my local MySQL and manually import it on the new server? Eww.
  2. Make the ANT script less grody (it's got lots of hardcoded directories in it right now) and run it on the server?
  3. The elegant option I don't know about?

The other complication is that the WAR will be going to different server(s) than the MySQL db will be on. Is there a Java book or web resource that comprehensively addresses these kinds of deployment issues?

A: 

You can use the Hibernate hbm2ddl task to create the schema for you. It won't populate any reference data, though. I often use a JUnit task and configuration to run it once and then go with it.

duffymo
+1  A: 

I've done something similar by creating ant targets to push an ant script to the remote machine, that ant script having a target to generate the DB. Since you already have ant targets to generate the schema and initialize the DB, you can just push your existing ant script to the remote machine (assuming the remote machine has the same set of tools).

You can use the scp ant task to do the remote copy, and sshexec to do the remote invocation of ant and the script.

sstair
+1  A: 

I think there are 3 options:

  1. Change your ANT script to target the DB on the remote machine. You can run it on your local machine, so you don't have to change it: It will find the necessary files in the same places. The main drawback of this method is that executing a lot of SQL over a network (internet) can be slow).
  2. Export the schema from your local (build) database to the new database. It doesn't have to be SQL, if your database supports some binary format. Usually this is the fastest and least error prone way of doing it, although there might be some very subtle issues if the configuration of the remote DB is just slightly different from your local setup (e.g. character set).
  3. Run the ANT script on your server. The biggest problem with this is that your database server will have to have all the necessary tools (like ant and java) but also all source files (hibernate mappings), which it usually (being a database server) has no need for.
Maarten Winkels
Thanks for the answer. It seems like number 2 is the most elegant of the 3 solutions.
Jason Maskell