Building this requires maven, tomcat, and MariaDB. Consult your Operating System Distribution's manual for installation instructions. It also uses git for source control.
For trouble with starting tomcat see the install guide.
For developer testing, the project's context.xml
is setup to expect a schema called blog
with the following configuration:
These credentials should be given minimal permissions to the rest of the database. While possible to do so, it is recommended not to use these credentials in a production system. Simply create a production user and edit context.xml
after deploying to use different credentials. See installation.
These SQL commands will create the blog
schema with the credentials as listed. this makes code-test-debug cycles easy, at minimal risk to the rest of the database.
CREATE SCHEMA blog; USE blog; SOURCE src/main/sql/setup.sql; GRANT SELECT, INSERT, UPDATE, DELETE ON blog.* TO 'blogger'@'localhost' IDENTIFIED BY 'bloggingit';
The project uses an additional schema called 'blogtest' for running unit tests. The unit tests need credentials to use this database, and reuse the above listed server credentials
To install the blogtest
schema and grant the blogger
user access, run the following queries. The project will automatically recreate the tables before each test run.
CREATE SCHEMA blogtest; USE blogtest; GRANT SELECT, INSERT, UPDATE, DELETE ON blogtest.* TO 'blogger'@'localhost' IDENTIFIED BY 'bloggingit';
Lastly the project requires a user account with full permissions to destroy and recreate the blogtest
schema. Run this query to create one, changing the username and password.
GRANT ALL PRIVILEGES ON blogtest.* TO 'username'@'localhost' IDENTIFIED BY 'password';
This allows maven build to destroy and recreate the blogtest
schema.
Since this user has all permissions it is necessary to use unique credentials and protect them. In Maven this can be done by hiding per-machine credentials in the .m2/settings.xml
file. Edit the file ~/.m2/settings.xml
to have the following. Ensure the id is set to localhost-mariadb-tester
so that the POM accesses the correct server.
<servers> <server> <id>localhost-mariadb-tester</id> <username>username</username> <password>password</password> </server> </servers>
There are two tomcat configuration items: the MariaDB JDBC driver jar, and the manager interface login.
To configure the MariaDB driver change directory to ${tomcat}/lib/
(where ${tomcat} is the installation location of tomcat) and run the following maven command.
cd ${tomcat}/lib/ mvn dependency:copy -Dartifact=org.mariadb.jdbc:mariadb-java-client:2.4.2:jar -DoutputDirectory=./
To grant the project permission to deploy the blog.war application, you will need to edit ${tomcat}/conf/tomcat-users.xml
. Make sure you have the following lines. Changing passwords to protect your development environment.
<!-- manager-gui is optional, but convenient if you want to deploy by hand --> <role rolename="manager-gui" /> <role rolename="manager-script" /> <user username="username" password="password" roles="manager-gui, manager-script" />
Again you should protect your server by hiding these credentials on the per-machine ~/.m2/settings.xml
file. Make sure that this time the id
is given as localhost-tomcat
.
<servers> <server> <id>localhost-tomcat</id> <username>username</username> <password>password</password> </server> </servers>
Now you should be ready to start developing. To build the project, as usual run
mvn package
And to deploy, redeploy, or undeploy the project WAR file to the development tomcat instance, run the following commands.
mvn tomcat7:deploy mvn tomcat7:redeploy mvn tomcat7:undeploy