Setting Up Your First AppFuse Project
AppFuse is a well known and commonly used starter web application to get you started on a J2EE app and is one of the most popular and top ranked/accessed projects on java.net. It was created by Matt Raible, who wrote the book Spring Live.
AppFuse? includes many useful libraries/binaries necessary for your app, including ant, javamail, spring, struts, junit, hibernate, mysql/postgresql jdbc drivers, and many more. It creates a directory structure based on best practices, provides a build.xml file which has options to compile, deploy, run tests, start/stop tomcat, and setup your database. The app even includes a sample application which shows the use of struts, spring, hibernate, JSF -- whichever source you decide to download. This tutorial will show you how to set up your environment to start using
AppFuse?.
- Install Tomcat (5.5.16) http://tomcat.apache.org/. Make sure you choose 5.5.16 because 5.5.15 has a bug where the ant reload command will fail with java.lang.NoClassDefFoundError. See http://raibledesigns.com/page/rd?entry=why_i_like_tomcat_5 for details on the problem.
- Install MySQL? (5.0.18) http://www.mysql.com/
- Install Ant (1.6.5) http://ant.apache.org/
- This tutorial uses cygwin so you may also want to install it as well. You can get it from http://www.cygwin.com.
- After installing, add system environment variables for each of root installation directories. Access this by right clicking My Computer and selecting properties. It is under: System Properties -> Advanced -> Environment Variables. The variables should look something like this:
ANT_HOME = C:\Development\ant
CATALINA_HOME = C:\Development\Apache Software Foundation\Tomcat 5.5
JAVA_HOME = C:\Program Files\Java\jdk1.5.0_06
- Append the $JAVA_HOME\bin, $ANT_HOME\bin, $CATALINA_HOME\bin, and your MySQL? bin directories to your PATH variable. It should look something like this:
PATH=.......;C:\Development\MySQL\MySQL Server 5.0\bin;%JAVA_HOME%\bin;%ANT_HOME%\bin;%CATALINA_HOME%\bin
- Edit Tomcat's tomcat-users.xml file and create a password for your admin user.
$ cd "$CATALINA_HOME/conf/"
$ vi tomcat-users.xml
<user username="admin" password="admin" roles="admin,manager"/>
- Access the mysql console and create a user with the ability to create databases and tables:
$ mysql -u root -p
> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY 'admin' WITH GRANT OPTION;
- Download AppFuse? 1.9 from https://appfuse.dev.java.net/. The Struts + Spring + Hibernate version is called: appfuse-1.9-src.zip
- Unzip to your workspace directory:
$ unzip appfuse-1.9-src.zip
- Create a new project using the "ant new" command in the appfuse directory. It will ask you to name your new application, choose a database, and a package name for your classes.
$ cd appfuse
$ ant new
What would you like to name your application [myapp]?
What would you like to name your database [mydb]?
What package name would you like to use [org.appfuse]?
- After your app has been created, cd to your app root directory and setup your database username and password in the build.properties file:
$ cd ../myapp/
$ vi build.properties
database.admin.username=admin
database.admin.password=admin
- In the same directory, edit the properties.xml file to use the tomcat user you created:
$ vi properties.xml
<property name="tomcat.username" value="admin"/>
<property name="tomcat.password" value="admin"/>
- The following command will create your database and tables, setup your webabb in Tomcat, and start the application.
$ ant setup-db setup-tomcat deploy
- You are done. The webapp should be setup on http://localhost:8080/myapp/. The database should already be setup with the user:
username: mraible
password: tomcat
References
--
JesseSuen - 02 Mar 2006