Development Environment Setup Walkthrough (2.5.x-2.8.x)
Information
This is a walkthrough for setting up a Sakai development environment on a laptop or desktop. These instructions will also work for setting up a development server though I suggest slightly beefier settings for memory. This is currently tailored for Sakai 2.5 - 2.8. Once you have a Sakai development environment setup you should be able to program your own Sakai tools or modify existing tools.
Notes for developers using Sakai 2.4.x-
- Developers who are using Sakai 2.4.x or lower should use the Development Environment Setup Walkthrough (2.2.x-2.4.x)
Notes for developers using Sakai 2.9.x+
- Developers who are using Sakai 2.9.x or higher (trunk after Sept 2011) should use the Development Environment Setup Walkthrough
Notes for windows users
- change the "/" to "\" for all directory paths except those specified in the maven build.properties file
- add the drive letter (C:) to your paths
- use %VARIABLE% instead of $VARIABLE with environment variables
- set your environment variables in Control Panel -> System -> Advanced -> Environment Variables
Zach Thomas has created a screencast which walks developers through setting up their Sakai 2.5 development environment
http://aeroplanesoftware.com/wordpress/wp-content/uploads/2008/01/developing-for-sakai-getting-started960x540.mov
http://aeroplanesoftware.com/wordpress/wp-content/uploads/2008/02/developing-for-sakai-setting-up-eclipse960x540.mov
All of sakai and related programs should be installed in an opt directory which you will need full write access to, put this directory anywhere you want, this document will assume you have placed it in your root directory
Install/Verify you have Java 1.5
- To check: Run java -version on the command line
- If not correct, download the J2SE SDK from:
- Sakai 2.7.x or less: http://java.sun.com/j2se/1.5.0/download.jsp
- Sakai 2.8 or higher: http://www.oracle.com/technetwork/java/javase/downloads/index.html
- Mac OS X users will have Java 1.5 or 1.6 by default
- Install it (the SDK) to /opt/java
- Note: Install the JRE to a different directory (probably the default, especially under windows) or you will have problems
- Set environment variable: JAVA_HOME=/opt/java
- Mac users: JAVA_HOME=/Library/Java/Home
- Windows users default: JAVA_HOME=C:\j2sdkXXX (where "XXX" is the version - for example "j2sdk1.5.0_11")
- Add $JAVA_HOME/bin to PATH
- Set JAVA_OPTS for tomcat in the tomcat/bin/setenv file (see Install Tomcat 5.5)
JAVA_OPTS='-server -Xmx964m -XX:MaxPermSize=172m -Djava.awt.headless=true'
- These settings are for developers
- More info on JVM server settings: Sakai Admin Guide - JVM Tuning
Install/Verify you have MySQL 4.1
- MySQL - http://www.mysql.com
- Some have reported that MySQL 5.0.x works just fine as well. If you already have this version, there's likely no point in downgrading to 4.1.*.
- To check: Run mysql --help on the command line
- If not, download MySQL from:
- Custom install to /opt/mysql (options vary slightly based on operating system)
- Linux users should install MySQL using a package or binaries if possible
- Choose standard configuration
- Install as a windows service (Windows only)
- Launch automatically (recommended)
- If you choose not to do this, make sure that you startup MySQL before you try to run Sakai
- Include the bin directory in Path
- Don't use an anonymous account
- Set your root password to "mysqlpwd1"
- MySQL - http://www.mysql.com
Setup Sakai DB (schema) and user
- Create the sakai database and sakai user (password=ironchef)
- Run the following from a command line prompt:
mysql -uroot -pmysqlpwd1
- Note: You can also do the following if you prefer to be prompted for the password: mysql -uroot -p
- Then run these commands from the mysql prompt (one command per line):
create database sakai default character set utf8; grant all privileges on sakai.* to 'sakai'@'localhost' identified by 'ironchef'; flush privileges; quit
- [Optional] Download and install mysql query browser
- http://dev.mysql.com/downloads/query-browser/1.1.html
- You do not have to do anything with query browser now
Download and setup Maven 2.0.6+ stable package
- Maven - http://maven.apache.org/
- Download Maven 2.2.X (minimum of 2.0.10) - http://maven.apache.org/download.html
- Extract to /opt (should create maven-2.X.X folder)
- Set environment variable: MAVEN2_HOME=/opt/maven-2.X.X
- Add $MAVEN2_HOME/bin to PATH\
- Set the MAVEN_OPTS environment variable
MAVEN_OPTS='-Xms256m -Xmx796m -XX:PermSize=64m -XX:MaxPermSize=136m'
- Adding -XX:+AggressiveOpts may speed up your builds depending on your OS, JVM, and system hardware
Install/Verify you have Subversion
- Subversion - http://subversion.tigris.org/
- To check: Run svn --version on the command line
- http://subversion.apache.org/packages.html
- Get the subversion binaries and not the source, if possible
- If there are no binaries for your platform, get the source and use the configuration options --with-ssl and --with-libs
- Extract to /opt (should create subversion-1.2.3)
- Windows users will want to rename the extracted directory
- Unix users will probably want to use a package for their flavor
- Set environment variable: SUBVERSION_HOME=/opt/subversion-1.2.3
- Add $SUBVERSION_HOME/bin to PATH
Download and setup tomcat 5.5.17+ (stable only)
- Apache Tomcat - http://tomcat.apache.org/
- Note: Always do a fresh install of Tomcat
- Note: Windows users should ensure that there are no spaces in the complete tomcat path as this causes errors with JSF tools in Sakai
GOOD: C:\opt\tomcat\, C:\sakaistuff\installs\tomcat\
BAD: C:\program files\tomcat\, C:\opt\apache tomcat 5.5.18\
- Download tomcat 5.5 - http://tomcat.apache.org/download-55.cgi
- Windows users should get the zip file instead of installing a service
It makes viewing the tomcat logs easier and it is easier to configure
- Windows users should get the zip file instead of installing a service
- Extract to /opt (symlink the apache-tomcat-5.5.x directory to tomcat after extracting)
- Windows users should just rename the directory since they cannot symlink
- Download the java 1.4.2 compat patch (compat.zip)
- NOTE: You should NOT install this patch if you are using Sakai 2.4 or higher
- Extract the files to the same location as tomcat itself
- Modify conf/server.xml for international character support
- Add URIEncoding="UTF-8" to the Connector element
- <Connector port="8080" URIEncoding="UTF-8" ...
- Add URIEncoding="UTF-8" to the Connector element
- Set environment variable: CATALINA_HOME=/opt/tomcat
- Add $CATALINA_HOME/bin to PATH
- Setup the SETENV file in the tomcat/bin directory with JAVA_OPTS (from Install Java 1.5+)
Mac/Linux: Create a file called setenv.shwith the following:
export JAVA_OPTS="-server -XX:+UseParallelGC -Xmx768m -XX:MaxPermSize=160m -Djava.awt.headless=true -Dhttp.agent=Sakai -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false -Dsun.lang.ClassLoader.allowArraySyntax=true"
Windows(PC): Create a file called setenv.batwith the following:
set JAVA_OPTS=-server -XX:+UseParallelGC -Xmx768m -XX:MaxPermSize=160m -Djava.awt.headless=true -Dhttp.agent=Sakai -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false -Dsun.lang.ClassLoader.allowArraySyntax=true
Download and setup MySQL Connector/J stable
- Mysql Connector J - http://www.mysql.com/products/connector/j/
- Download connector for your version of MySQL
- If running mySQL 4.1
Download version 3.1.12+ from http://dev.mysql.com/downloads/connector/j/3.1.html - If running MySQL 5.0.x
Download version 5.0.4+ from http://dev.mysql.com/downloads/connector/j/5.0.html
- If running mySQL 4.1
- Extract the file to /opt
- Copy mysql-connector-java-<version>-bin.jar to $CATALINA_HOME/common/lib
- Delete the extracted folder
Use Subversion to download sakai cafe trunk
- Change to the /opt directory
- svn checkout https://source.sakaiproject.org/svn/cafe/trunk/ cafe_trunk
- If you want a version other than this one, browse the tags and branches at https://source.sakaiproject.org/svn/cafe/
- subversion will create a "trunk" directory for you,
you can use any directory name you like, just add a name after the checkout location:
svn checkout https://source.sakaiproject.org/svn/cafe/trunk/ cafe-trunk
- Checkout will take about 5-10 minutes
- The directory created by subversion will be referred to as <sakai-src> directory
Setup sakai.properties file
- Create sakai directory in $CATALINA_HOME
- $CATALINA_HOME should be /opt/tomcat if you have been following these instructions
- Note: There were previously two configuration files, sakai.properties and placeholder.properties. These have now been combined into sakai.properties. You can attempt to manually combine the two files from a previous version, but it's better to start with the sample included with the sakai source in the reference directory.
- Copy sakai.properties from <sakai-src>/reference/docs to $CATALINA_HOME/sakai
- Note: This file may not be in your checkout if you have acquired one of the older versions of cafe - you can fetch it manually from here https://source.sakaiproject.org/svn/reference/trunk/docs/sakai.properties.
Make sure you get the sakai.properties for the version of Sakai you are using (e.g. Sakai 2.4.x):
http://source.sakaiproject.org/svn/reference/branches/sakai_2-4-x/docs/sakai.properties
- Note: This file may not be in your checkout if you have acquired one of the older versions of cafe - you can fetch it manually from here https://source.sakaiproject.org/svn/reference/trunk/docs/sakai.properties.
- Edit the sakai.properties file for a MySQL dev environment. Starting at the section # DATABASE CONFIGURATION:
- Set BaseDataSource username
- Set username@javax.sql.BaseDataSource=sakai
- Set BaseDataSource password
- Set password@javax.sql.BaseDataSource=ironchef
- Find the section: ## HSQLDB settings and comment out 7+ lines in it
## HSQLDB settings - on by default #vendor@org.sakaiproject.service.framework.sql.SqlService=hsqldb #driverClassName@javax.sql.BaseDataSource=org.hsqldb.jdbcDriver #hibernate.dialect=org.hibernate.dialect.HSQLDialect #validationQuery@javax.sql.BaseDataSource=select 1 from SYSTEM_USERS # two hsqldb storage options: first for in-memory (no persistence between runs), second for disk based #url@javax.sql.BaseDataSource=jdbc:hsqldb:. #url@javax.sql.BaseDataSource=jdbc:hsqldb:${sakai.home}/db/sakai.db
- Find the section: ## MySQL settings and uncomment the 6+ lines in it
## MySQL settings - make sure to alter as appropriate vendor@org.sakaiproject.db.api.SqlService=mysql driverClassName@javax.sql.BaseDataSource=com.mysql.jdbc.Driver hibernate.dialect=org.hibernate.dialect.MySQLDialect url@javax.sql.BaseDataSource=jdbc:mysql://127.0.0.1:3306/sakai?useUnicode=true&characterEncoding=UTF-8 validationQuery@javax.sql.BaseDataSource=select 1 from DUAL defaultTransactionIsolationString@javax.sql.BaseDataSource=TRANSACTION_READ_COMMITTED
- Note that this line may be incorrect in the default file, it should read as shown:
vendor@org.sakaiproject.db.api.SqlService=mysql
- Set BaseDataSource username
- Save the changes to the file
- Create sakai directory in $CATALINA_HOME
Create maven settings.xml file
- Create a new xml file in your user home directory in the .m2 directory called settings.xml
- Note: This is probably c:\documents and settings\<username> in Windows
- Download a sample settings.xml file (setup for windows users)
- Add the following lines:
<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <profiles> <profile> <id>tomcat5x</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <appserver.id>tomcat5x</appserver.id> <appserver.home>/opt/tomcat</appserver.home> <maven.tomcat.home>/opt/tomcat</maven.tomcat.home> <sakai.appserver.home>/opt/tomcat</sakai.appserver.home> <surefire.reportFormat>plain</surefire.reportFormat> <surefire.useFile>false</surefire.useFile> </properties> </profile> </profiles> </settings>
- Note: Unfortunately, Sakai does not use the standard appserver.home so you have to specify a sakai.appserver.home
- Note: The sakai.appserver.home must be C:\opt\tomcat for windows users
- Note: Do not include trailing / or \ slashes in the directory paths
- (optional) You can specify the tomcat home to be an environment variable like so:
<maven.tomcat.home>${env.CATALINA_HOME}</maven.tomcat.home>
- (optional) Users who use a network proxy need to add the following to their file
... <proxies> <proxy> <active>true</active> <protocol>http</protocol> <host>www.your.proxy.host</host> <port>80</port> <username>your_username</username> <password>your_password</password> <nonProxyHosts>localhost</nonProxyHosts> </proxy> </proxies> </settings>
- If you do not use a username or password for your proxy just leave out those 2 lines
- You only need the nonProxyHosts option if you have a local maven repo that does not require the proxy to be accessed
- Note: Maven 2 doesn't support Microsoft's NTLN authentification scheme. If you connect to a proxy like ISA you will need to use a tool, such as http://ntlmaps.sourceforge.net/ to proxy your traffic
- Create a new xml file in your user home directory in the .m2 directory called settings.xml
Use Maven to build Sakai
- Open a command line shell
- Change directory to /opt/<sakai-src>
- Execute mvn -Pcafe clean install to build Sakai using maven
- Note: The build will take an extra 5-10 minutes to download dependencies the first time
- Execute mvn -Pcafe sakai:deploy to deploy Sakai to your tomcat using maven
- Unlike in maven1, the maven2 Sakai plugin downloads automatically (this allows you to deploy the parts of projects to the right locations in tomcat)
- Partial builds are supported by the maven2 build system
You can now do a "mvn clean install sakai:deploy" from any subdirectory and build just that code - Once you have downloded the jars you can run maven off-line with mvn -o clean install sakai:deploy
Start Tomcat and check to make sure Sakai runs
- Start tomcat using $CATALINA_HOME/bin/startup
- Allow 1 minute+ for tomcat to start up
- Open http://localhost:8080/ to verify tomcat is running
- Open http://localhost:8080/portal to verify sakai is running
- Login to sakai as username:admin, password:admin
- Shutdown Tomcat using $CATALINA_HOME/bin/shutdown
Install Eclipse 3.2+ stable
- Eclipse - http://www.eclipse.org/
- Note: If you already have eclipse 3.1.x installed, your best best is to start over with a fresh install rather than attempting to upgrade
- Note: If you have not installed eclipse already, you should download the WebTools Platform: All-in-one package for Eclipse 3.3+ which includes Eclipse and all of the necessary webtools packages, this is much faster and easier than downloading them seperately, you can skip the WebTools step if you do this, here are instructions to install the Eclipse WebTools
- Download the newest stable version http://www.eclipse.org/
- Extract the downloaded file to /opt
- Windows users should extract to c:\
- Mac users should use the installer and put it in Applications
- Run eclipse to verify it works (/opt/eclipse/eclipse)
- Windows users: c:\eclipse\eclipse.exe to run eclipse
- Note: If it does not work, there is probably a problem with your java install
- Set the memory settings for Eclipse
- The default memory settings for Eclipse are much too low to handle the number of webapps in a full Sakai installation
- Shutdown eclipse if it is running
- Edit the eclipse.ini file in the directory you extracted/installed eclipse
- Change the settings from something like this:
to something like this (leave any params that do not match these alone):
-vmargs -Xms40m -Xmx256m
--launcher.XXMaxPermSize 256M -vmargs -Xms128m -Xmx1024m -XX:+UseParallelGC
- Windows users should not use notepad to edit this file, use wordpad or edit (command line)
- Mac users will need to take additional steps to edit the eclipse.ini file
- Control-click on the Eclipse Application icon and select Show Package Contents
- Double-click on the Contents folder
- Double-click on the MacOS folder, the eclipse.ini file should be here
- Full path: eclipse/Eclipse.app/Contents/MacOS/eclipse.ini
- Set the JVM
- The default JVM will be the one in the JRE, things will work better if you change this to the one in the J2SE
- Startup eclipse if it is not running
- Select Window -> Preferences -> Java -> Installed JREs
- Select the current installed JRE
- Click the Edit button
- Click Browse and navigate to the home directory of your JAVA installation (e.g. /opt/java)
- Click OK to save and then OK to Finish
- Running Eclipse with a different JVM from the default
Add-vm /opt/java/bin/java
after the eclipse executable - You must include the full path to the java executable file
- Running Eclipse with a different JVM from the default
- More Eclipse tips here: Eclipse notes
- Eclipse - http://www.eclipse.org/
Add Eclipse Web Tools Project (WTP)
- Web Tools Project - http://www.eclipse.org/webtools/
- NOTE: Installing the all-in-one-package or manually installing are far more reliable and definitely recommended over using the updater method (the last one)
- NOTE: Only install released versions, the development versions tend to be unstable and buggy
- WebTools Platform: All-in-one (fastest, recommended)
- This should only be used if you do not already have Eclipse installed
- Go to eclipse downloads
- Older versions at WTP downloads
- Click Eclipse IDE for Java EE Developers and choose a download mirror
- Extract the package to whereever you want to install eclipse (normally your drive root /eclipse)
- Adjust the config as indicated in Install Eclipse 3.2+
- Startup Eclipse
- Manual installation (faster)
- Download WTP 1.5.x (Eclipse 3.2) or 2.0.x (Eclipse 3.3) to your desktop
- Shutdown Eclipse
- Extract the package to your Eclipse installation directory
- Startup Eclipse
- Install using the Eclipse updater (somewhat easier but not recommended)
- Start eclipse
- Select Help -> Software Updates -> Find and Install
- Select Search for new features to install, click Next
- Choose the Eclipse.org Update Site (or The Eclipse Project Updates) and click Finish
- Select WTP 0.7 (or newer)
- Note: If it is not listed, use the following update URL: http://download.eclipse.org/webtools/updates/
- Click Select Required
- Click Next and follow installation instructions
- Accept terms, click Finish
- Click Install All
- Restart the workbench when asked
Add subclipse to Eclipse
- Subclipse - http://subclipse.tigris.org/
- Startup eclipse
- Select Help -> Software Updates
- Select Available Software, click Next
- Click Add Site
- Enter http://subclipse.tigris.org/update_1.6.x for the URL
- Click Finish
- Check the Subclipse box and click Next
- Ignore the integrations unless you have a need for them, they can stop the install from working
- Accept terms, click Next, click Finish, click Install All
- Restart the workbench when asked
- Add bin and target to global svn ignore in Eclipse (Optional)
- This will keep you from committing bin and target directory files when you add projects to svn
- Click on Window -> Preferences
- Select Team -> Ignored Resources
- Click on Add Pattern and enter "bin"
- Click on Add Pattern and enter "target"
- Click on Add Pattern and enter "m2-target"
- Click on Apply and then OK
Add Maven Eclipse Plugin to Eclipse
- Maven Plugin for Eclipse - http://m2eclipse.codehaus.org/
- Startup eclipse
- Select Help -> Software Updates
- Select Available Software, click Next
- Click Add Site
- Enter http://m2eclipse.sonatype.org/sites/m2e for the URL
- Click Finish
- Expand the Maven Integration for Eclipse update site
- Check the Maven Integration box and click Next
- Ignore the optional parts unless you have a need for them
- Accept terms, click Next, click Finish, click Install All
- Restart the workbench when asked
Import Sakai source code into Eclipse
[OPTIONAL] Run the following maven commands in your sakai-src root folder (e.g. /opt/cafe-2.5.x)
This will clean out any eclipse files that are in there already:mvn eclipse:clean
[OPTIONAL] Generate the eclipse files using maven (this is not required and not recommended)
This will generate valid eclipse .project and .classpath files from the maven buildmvn eclipse:eclipse
Special Case: If your workspace is in a different location, I've found that this option is needed passed to maven, otherwise the dependencies get incorrect. -Declipse.workspace=..
- Passing the full path to the local workspace or current directory might also work
If you are using the Maven Plugin for Eclipse then you should run this instead:
mvn eclipse:m2eclipse
- Startup eclipse if it is not running
- Create a new workspace for Sakai
- Click on File -> Switch Workspace
- Enter "WS-Sakai" in place of the default "workspace" directory
- Click OK (eclipse will restart)
- The following steps should be done in the WS-Sakai workspace
- Add Maven Repository libraries to classpath
- NOTE: This is for backwards compatibility with projects using the M2_REPO variable so it can be skipped
- Select Window -> Preferences -> Java -> Build Path -> Classpath Variables
- Add MAVEN_REPO classpath variable with the path to the local maven repository (Sakai 2.4 or lower)
- The path should be: $USER_HOME/.maven/repository
- Add M2_REPO classpath variable with the path to the local maven repository (Sakai 2.5 or higher)
- The path should be: $USER_HOME/.m2/repository
- Switch to the Java perspective (Window -> Open Perspective -> Java)
- Make sure you are in the package explorer
- Turn off Automatic builds
- Select Project and uncheck Build automatically
- Select File -> Import -> Existing Projects into Workspace
- You can either import the entire sakai source tree (e.g. /opt/sakai-2.9.x) or selectively choose specific sub-projects you'll be working on (e.g. /opt/sakai-2.9.x/announcement)
- Click Finish to import the selected projects
- This will take awhile, probably 5+ minutes
- Clean all Sakai projects
- Select Project -> Clean
- Select Clean all projects
- Check Start a build immediately
- Click OK
- Build All (Project -> Build All)
- There will be hundreds of warnings, do not worry about these
- Turn back on Automatic builds
- Select Project and check Build automatically
- Select project and then use the down triangle menu to add Filters (target, m2-target)