Skip to content

Development notes

jscoles edited this page May 12, 2012 · 3 revisions

Development notes

To work on the mouse inventory using Eclipse on your development system, follow these general instructions.

Fork the repository

On github, log in with your github account. From the mouseinventory repository on github, click 'fork'. This will make a copy of the repository under your account that you will have full write access to.

You'll be working against this repository, not the main one under the organization UCSF-MouseDB. If you make changes that you think should be included in the main repository, you'll want to submit a well-formed pull request.

Clone your forked repository on your development system

cd my_code_directory
git clone git@github.com:mygitusername/mouseinventory.git

If you have trouble forking or cloning, check out the github help section.

Working with maven

Maven is a build and dependency management tool in wide use within the java community. You'll want to install maven2, and set it up so that you can run 'mvn' from the command line. For details, see http://maven.apache.org/.

To download the initial dependencies, run maven:

cd mouseinventory
mvn package

This will download all of the dependencies specified in the pom.xml file, and put them in your local maven repository (~/.m2/). The .classpath file that eclipse looks at expects all of the jars to be there. If you make changes to pom.xml, you'll want to run the maven eclipse plugin to update the .classpath for eclipse:

cd mouseinventory
mvn eclipse:eclipse -Dwtpversion=1.5

Download tomcat

Download apache tomcat 6, and unzip it.
On windows, something like c:\apache\ is a good choice. On mac, you can just put it in /Applications/

You don't need to do anything but download it, later you'll be pointing eclipse at this directory. You (probably) don't want tomcat running all the time, just when you need it for debugging.

Install Eclipse

Download and install the Eclipse IDE for J2EE developers: http://www.eclipse.org/downloads/. Download and install the M2eclipse plugin http://www.sonatype.org/m2eclipse. (From eclipse, go to help, install new software. Add this url to the list of software sites: http://download.eclipse.org/technology/m2e/releases, and then install the plugin.

In eclipse, add the project to your workspace.
File -> Import -> 'exisiting projects into workspace'. Choose the mouseinventory directory as the root.

Make sure that you can build the project - there shouldn't be any java errors in the Markers window.

Add a tomcat server in eclipse, for easy debugging:

Eclipse -> preferences -> Servers -> Runtime Environments Add apache tomcat 6; you will have to point it at the directory where you downloaded tomcat. If you get an add and remove window, add the mouseinventory project, and you're set. If you don't, open the Servers view (Window -> View -> Servers), and right click the tomcat server in the list. Choose add and remove..., then add the server.

You can now use the servers window to start, stop, restart, and debug right from eclipse. If you get errors about a port already being in use, then you probably are running something else on port 8080. Either stop that other process, or use a different port in server.xml. (See below)

To edit the server configuration files, open the servers tree in the eclipse project explorer. Under the tomcat server, you should see a context.xml, tomcat-users.xml, etc. Edit these files just as you would if installing the database on a production server - add the user roles, environment variables, and JDBC datasource. Start from the template files in the serverFiles directory in the mouseinventory repo.

Once everything builds (no errors anywhere, it may take a few project-> clean commands and refreshes to get to this point), you can run the server. In the server tab, select the server and click the green arrow (Run).

In a web browser, go to http://localhost:8080/mouseinventory. If about.jsp loads up, you are are good to go.

The rest of the site won't work until you set up the database.

Set up the database

Install mysql server http://www.mysql.com/downloads/mysql/ You need to have it installed such that you can run 'mysql' from a command line, and get a mysql prompt.

mysql -uroot -p

Should prompt you for the root password that you provided when you installed the server.
If you see a mysql prompt like the one below, you did it right. If not, make sure that you have mysql server installed and properly configured. You might need to add the mysql/bin directory to your path.

Create a new database:

IMPORTANT - replace 'YOUR_PASSWORD_HERE' with your password for mouseuser - the account used by the application

mysql -u root -p
(enter your root password at the prompt, if you have one)
mysql>create database mouse_inventory;

CREATE DATABASE mouse_inventory;
CREATE USER 'mouseuser'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD_HERE';
GRANT SELECT,UPDATE,INSERT,DELETE ON mouse_inventory.* TO 'mouseuser'@'localhost' WITH GRANT OPTION;

quit;

Import the blank database file into your local database:

> mysql -uroot -p mouse_inventory < database\blankdb.sql

Run through the dbmods to bring the schema up-to-date. TODO - use an actual database migration framework so this isn't so painful.

Now, try loading the 'holder list' in your browser. If you don't see any errors, and see one 'default holder', you are all set.

Building distributions (.war files)

If you need a war file to FTP to a server, just use maven. Run 'mvn package' from the project directory. The war is created in the target/ directory.

However, the preferred setup is to configure your server to pull changes from github, and deploy with maven. With that, you'll never have to copy war files manually. See the installation page on the wiki for details.