For a number of years we are doing hippo development using our beloved tool "Intellij". We can import the project using the pom. Deploying from within Intellij was done using the maven provided jetty integration to run the cms. Then we would run the site in another tomcat or as well from maven with jetty. Not very fast, but it works. In release 7.6 (I think) hippo changed the deployment model. They have provided a mechanism to use cargo from maven to start the cms as well as the site within one tomcat instance.
If you want to give the default mechanism a spin, create a new project using the hippo maven archetype and use the cargo integration to run the new project. Steps on how to do this and some links will be presented later on.
Not all developers are the same, maybe some of them still want to use cargo and others want to pick up the challenge and use a tool like eclipse to do the job. Therefore we want to have a mechanism that supports most of the developers out there.
In this blogpost I am going to show you how you can create a structure supporting all these different deployment options. Of course the demonstration that it works is done with Intellij.
Using the Hippo maven archetype.
Documentation about using an archetype is not required to be very extensive. Hippo has written enough documentation on their site about what they call Baby Steps.
First you need to check the latest and greatest version of the archetype. You can find them at the following url:
In my case the latest and greatest version is 1.05.02. The following command creates a new project based on the hippo archetype.
mvn archetype:generate \ -DarchetypeRepository=http://maven.onehippo.com/maven2 \ -DarchetypeGroupId=org.onehippo.cms7 \ -DarchetypeArtifactId=hippo-archetype-website \ -DarchetypeVersion=1.05.02
You are being asked the name for your project. I just took the default. Now my directory structure looks like this:
Check out the readme file for all the options. Time to check if the application is actually doing something. More information can be found at the following location
[~/temp/hippo/myhippoproject]$ mvn clean install [~/temp/hippo/myhippoproject]$ mvn -P cargo.run
Before I forget, usually the internet gets downloaded right now, thank you maven.
To see if it works, check the following urls.
Migrating to a structure with intellij
Now import everything into intellij. Create a new project, choose the from external model option and after that maven. Browse to the location where you created the archive and chose the checkboxes you like. I usually start with this:
Change the conf folder for Cargo
We start off by making the conf folder a real maven project. That way we can use the assembly plugin to create the tomcat base folder. The config files for cargo are moved to the folder src/cargo. Of course we also need to change the cargo configuration to reflect that change. You need to change the location of the context.xml file as well as the log4j-dev.xml. They can both be found in the pom.xml in the root of the project at the bottom in the part where the cargo-maven2-plugin is configured.
To make sure it works, you can run the project with cargo again like before.
Create the tomcat base folder
So everything is still running with cargo. We want to create a normal tomcat runner. To realize this we can use the provided distribution using the assembly plugin. Have a look at the src folder in the root of the project. This contains a distribution.xml. I have reused part of this configuration to generate a base folder for tomcat. In the pom of the conf project we configure the assembly plugin. The parent for this pom is the parent of the complete project, that way we inherit the hippo versions. The assembly configuration should not be to hard to figure out. The configuration for tomcat to be used by the assembly plugin is shown in the next code block:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>config-local</id> <formats> <format>dir</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>src/tomcat</directory> <outputDirectory>/</outputDirectory> <directoryMode>755</directoryMode> </fileSet> </fileSets> <dependencySets> <dependencySet> <useProjectArtifact>false</useProjectArtifact> <outputDirectory>/shared/lib</outputDirectory> <scope>provided</scope> <directoryMode>755</directoryMode> <includes> <include>org.onehippo.cms7:hippo-repository-api</include> <include>org.onehippo.cms7:hippo-repository-builtin</include> <include>org.onehippo.cms7:hippo-cms-sso</include> <include>org.onehippo.cms7:hippo-addon-publication-workflow-common</include> <include>org.onehippo.cms7.hst:hst-api</include> <include>org.onehippo.cms7.hst:hst-commons</include> <include>log4j:log4j</include> <include>org.slf4j:slf4j-api</include> <include>org.slf4j:slf4j-log4j12</include> <include>org.slf4j:jcl-over-slf4j</include> </includes> </dependencySet> <dependencySet> <useProjectArtifact>false</useProjectArtifact> <outputDirectory>/common/lib</outputDirectory> <scope>provided</scope> <directoryMode>755</directoryMode> <includes> <include>javax.jcr:jcr</include> <include>javax.mail:mail</include> <include>org.apache.geronimo.specs:geronimo-jta_1.1_spec</include> <include>javax.jdo:jdo2-api</include> </includes> </dependencySet> </dependencySets> </assembly>
In the first few lines we configure the end result being a directory and everything obtained through the file sets is placed in the root of this directory. The file set is what we have placed under src/tomcat. The libraries for the common lib and the shared lib are obtained through dependency sets. This way we obtain the right versions of the hippo jars. Do not forget to run the maven project again after version changes in the libraries.
The final step is to provide the files required by tomcat. The bin folder contains the setenv.sh and setenv.bat. These files are used by tomcat to set some environment variables. The conf folder contains configuration files like catalina.properties, logging.properties and the hippo configuration for the repository, repository.xml. Check the zip file that is attached to this blog post.
Configure Tomcat in intellij
First you have to build the conf project. The tomcat base folder than is within the target folder. Now you have to add a tomcat server. Go to configurations, add new configuration and choose tomcat local. In the wizard go the the configuration of Application Server and add a new server using the following base and home folder:
Than go to the deployment tab. Add the site as well as the cms. After that it is good to add a startup parameter to enforce the location of the repository. Add the following line to the vm options
Now you should be ready to run tomcat and everything should be working.