Web project from development to production

Create a project with the maven archetype :

mvn archetype:generate -DarchetypeCatalog=http://maven.jahia.org/maven2

Full web projects in one place (templates and modules)

Choose jahia-app-archetype (4)

If you want to split your templates and your functional modules then first create a template project (5) then you will create modules projects as needed.

Create a template project :

  • artifactId = mycustomtemplateset
  • jahiaPackageVersion = (name of the jahia version you want to use) (for example 6.6.0.0)
  • moduleName = myCustomTemplateSet

Content of your project :

mycustomtemplateset
+── src
    +── main
    +   +── import
    +   +── java
    +   +── resources
    +   │   +── META-INF
    +   +── webapp
    +       +── META-INF
    +       │   +── spring
    +       +── css
    +       +── icons
    +       +── img
    +       +── javascript
    +       +── jnt_template
    +       │   +── html
    +       +── resources
    +       +── scripts
    +── site
        +── apt

In src/main/webapp/resources rename __resourceBundleName__.properties with moduleName.properties (ex:myCustomTemplateSet.properties). Note that spaces in moduleName will be removed to be used for the resource bundle file. So if your moduleName was "My Custom Template Set" the properties file should be MyCustomTemplateSet.properties

Now make sure you jahia is running

Build and deploy your newly created template set using maven

mvn install jahia:deploy

inside your Jahia you should see something like this in the console :

2012-01-11 11:32:03,223: INFO  [TemplatePackageDeployer] - Start deploying new module package 'myCustomTemplateSet' version=1.0-SNAPSHOT
2012-01-11 11:32:03,230: INFO  [TemplatePackageDeployer] - Deploying JARs for module myCustomTemplateSet
2012-01-11 11:32:03,390: INFO  [JackrabbitStoreProvider] - Custom node types registered for myCustomTemplateSet in 130 ms
2012-01-11 11:32:03,400: INFO  [TemplatePackageRegistry] - Registered myCustomTemplateSet version=1.0-SNAPSHOT
2012-01-11 11:32:03,415: INFO  [TemplatePackageApplicationContextLoader] - Reloading Spring application context for Jahia modules
2012-01-11 11:32:04,527: INFO  [JobSchedulingBean] - Deleting job Maintenance.VisibilityActionPurgeJob
2012-01-11 11:32:04,562: INFO  [JobSchedulingBean] - Scheduling persistent job Maintenance.VisibilityActionPurgeJob
2012-01-11 11:32:04,585: INFO  [JobSchedulingBean] - Deleting job SitemapJob.SitemapJob
2012-01-11 11:32:04,585: INFO  [JobSchedulingBean] - Scheduling RAM job SitemapJob.SitemapJob
2012-01-11 11:32:04,587: INFO  [TemplatePackageApplicationContextLoader] - Jahia modules application context reload completed in 1172 ms
2012-01-11 11:32:04,639: INFO  [TemplatePackageDeployer] - Checking for missing module nodes and initializing 0 of them took 52 ms
2012-01-11 11:32:05,174: INFO  [RulesListener] - Rules executed for live [/templateSets/mycustomtemplateset, /templateSets/mycustomtemplateset/j:wcagCompliance] in 1ms
2012-01-11 11:32:05,441: INFO  [RulesListener] - Rules executed for live [/templateSets/mycustomtemplateset/jcr:mixinTypes, /templateSets/mycustomtemplateset/priority, /templateSets/mycustomtemplateset/changefreq] in 0ms
2012-01-11 11:32:05,479: INFO  [RulesListener] - Rules executed for default [/templateSets/mycustomtemplateset/templates/contents, /templateSets/mycustomtemplateset/templates/files, /templateSets/mycustomtemplateset/contents] ... and 3 other nodes in 116ms
2012-01-11 11:32:05,492: INFO  [TemplatePackageDeployer] - Starting import for the module package 'myCustomTemplateSet' including: [META-INF/import.zip]
2012-01-11 11:32:05,521: INFO  [TemplatePackageDeployer] - ... importing /home/user1/Ent-Jahia_xCM_v6.6/tomcat/webapps/ROOT/modules/mycustomtemplateset/META-INF/import.zip into /
2012-01-11 11:32:05,524: ERROR [DocumentViewImportHandler] - Couldn't find definition for property j:displayInMenu
2012-01-11 11:32:05,857: INFO  [RulesListener] - Rules executed for live [/templateSets/mycustomtemplateset/j:installedModules, /templateSets/mycustomtemplateset/j:siteType] in 0ms
2012-01-11 11:32:05,918: INFO  [RulesListener] - Rules executed for default [deleted /templateSets, deleted /templateSets/mycustomtemplateset/templates/files, deleted /templateSets/mycustomtemplateset/templates/contents] ... and 23 other nodes in 20ms
2012-01-11 11:32:06,025: INFO  [RulesListener] - Rules executed for live [/templateSets/mycustomtemplateset/j:installedModules, /templateSets/mycustomtemplateset/j:title, /templateSets/mycustomtemplateset/j:dependencies] in 1ms
2012-01-11 11:32:06,062: INFO  [RulesListener] - Rules executed for default [/templateSets/mycustomtemplateset/j:siteType, /templateSets/mycustomtemplateset/j:installedModules, /templateSets/mycustomtemplateset/j:title] ... and 1 other nodes in 1ms
2012-01-11 11:32:06,063: INFO  [TemplatePackageDeployer] - ... finished initial import for module package 'myCustomTemplateSet'.
2012-01-11 11:32:06,063: INFO  [ComponentRegistry] - Start registering UI droppable components...

Now connect to your Jahia instance at http://127.0.0.1:8080/start and modify your template set using the studio, add some images/css/javascript as needed see the Jahia Template Development Documentation for more information about this.

Once your template set looks near its done, export it, update your repository.xml file with the new content.

To export it, select "Export" from Export the top menu

And open the xml file

Copy the content of the xml file to the ./src/main/import/repository.xml file

Create a site with your template set (go to administration for that).

From now on you can update your template (if modifying files you need to redeploy your template set) and/or create content on your site.

When your site is ready to be exported go to administration export the whole site, you will get a zip containing everything to import your site.

You can now deploy your templates and all necessary modules on another server and then import this file when creating a new site.

Or you can create another project and store your site in it, then use maven to package it and then deploy it into jahia. Here how to achieve that :

  • Create a new directory at the same level you create your mycustomtemplateset project call it mycustomsite
  • Now create a pom.xml file like this one at the root of your project :
    <?xml version="1.0" encoding="UTF-8"?>
    <project 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/maven-4.0.0.xsd">
        <parent>
            <groupId>org.jahia.prepackagedsites</groupId>
            <artifactId>prepackagedSites</artifactId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
        <artifactId>mycustomsite</artifactId>
        <version>1.0-SNAPSHOT</version>
        <name>My Custom Site</name>
        <packaging>pom</packaging>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>ACME</id>
                            <configuration>
                                <descriptors>
                                    <descriptor>src/main/assembly/mycustomsite.xml</descriptor>
                                </descriptors>
                                <attach>false</attach>
                                <finalName>myCustomSite</finalName>
                                <appendAssemblyId>false</appendAssemblyId>
                            </configuration>
                            <phase>validate</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>users</id>
                            <configuration>
                                <descriptors>
                                    <descriptor>src/main/assembly/users.xml</descriptor>
                                </descriptors>
                                <attach>false</attach>
                                <finalName>users</finalName>
                                <appendAssemblyId>false</appendAssemblyId>
                            </configuration>
                            <phase>validate</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>systemsite</id>
                            <configuration>
                                <descriptors>
                                    <descriptor>src/main/assembly/systemsite.xml</descriptor>
                                </descriptors>
                                <attach>false</attach>
                                <finalName>systemsite</finalName>
                                <appendAssemblyId>false</appendAssemblyId>
                            </configuration>
                            <phase>validate</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>root</id>
                            <configuration>
                                <descriptors>
                                    <descriptor>src/main/assembly/root.xml</descriptor>
                                </descriptors>
                                <appendAssemblyId>false</appendAssemblyId>
                            </configuration>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
  • Now create folders src/main, then expand your site zip file inside src/main, you will have several zip files and one property file.
  • Copy the property file in a folder named root
  • Extract the content of systemsite inside a folder named system site
  • Extract the content of users in src/main (users.zip contains a folder already named users)
  • Now we will create the assembly files that will repackage everything together :
    • in src/main/assembly create mycustomsite.xml as this one:
      <assembly>
          <id>ACME</id>
          <includeBaseDirectory>false</includeBaseDirectory>
          <formats>
              <format>zip</format>
          </formats>
          <fileSets>
              <fileSet>
                  <directory>${basedir}/src/main/myCustomSite</directory>
                  <includes>
                      <include>**/*</include>
                  </includes>
                  <outputDirectory></outputDirectory>
              </fileSet>
          </fileSets>
      </assembly>
    • in src/main/assembly create systemsite.xml as this one:
      <assembly>
          <id>systemside</id>
          <includeBaseDirectory>false</includeBaseDirectory>
          <formats>
              <format>zip</format>
          </formats>
          <fileSets>
              <fileSet>
                  <directory>${basedir}/src/main/systemsite</directory>
                  <includes>
                      <include>**/*</include>
                  </includes>
                  <outputDirectory></outputDirectory>
              </fileSet>
          </fileSets>
      </assembly>
    • in src/main/assembly create users.xml as this one:
      <assembly>
          <id>users</id>
          <includeBaseDirectory>false</includeBaseDirectory>
          <formats>
              <format>zip</format>
          </formats>
          <fileSets>
              <fileSet>
                  <directory>${basedir}/src/main/users</directory>
                  <includes>
                      <include>**/*</include>
                  </includes>
                  <outputDirectory></outputDirectory>
              </fileSet>
          </fileSets>
      </assembly>
    • in src/main/assembly create root.xml as this one:
      <assembly>
          <id>root</id>
          <includeBaseDirectory>false</includeBaseDirectory>
          <formats>
              <format>zip</format>
          </formats>
          <fileSets>
              <fileSet>
                  <directory>${basedir}/src/main/root</directory>
                  <includes>
                      <include>**</include>
                  </includes>
                  <outputDirectory></outputDirectory>
              </fileSet>
              <fileSet>
                  <directory>${basedir}/target</directory>
                  <includes>
                      <include>myCustomSite.zip</include>
                  </includes>
                  <outputDirectory></outputDirectory>
              </fileSet>
              <fileSet>
                  <directory>${basedir}/target</directory>
                  <includes>
                      <include>users.zip</include>
                  </includes>
                  <outputDirectory></outputDirectory>
              </fileSet>
              <fileSet>
                  <directory>${basedir}/target</directory>
                  <includes>
                      <include>systemsite.zip</include>
                  </includes>
                  <outputDirectory></outputDirectory>
              </fileSet>
          </fileSets>
      </assembly>

Now your mycustomsite folder should like something like that :

   |-src
   |---main
   |-----assembly
   |-----myCustomSite
   |-------content
   |-----root
   |-----systemsite
   |-----users
   |-------content

Now install a production env on your server, do not start your jahia yet.

Deploy all necessary modules you might need for your project especially your mycustomtemplateset war file using the deployModule.sh (or deployModule.bat) script provided by Jahia :

 deployModule module1.war [module2.war ...] tomcat/webapp/ROOT

Inside Ent-Jahia_xCM_v6.6.0.0/tomcat/webapps/ROOT/WEB-INF/var create if missing the following folder : prepackagedSites

Then copy mycustomsite/target/mycustomsite-1.0-SNAPSHOT.zip inside this prepackagedSites folder

Now start your jahia, import your site and enjoy

From now on you can deploy new version of your templateset inside the shared module, then you will have to go to your site administration to deploy your template on your site as their is no studio on production env.

Of roles and permissions :

If ever you need some particular permissions and/or roles on your project keep in mind that those are imported with their own file, they are not part of an export and so need to be placed alongside your repository.xml file in your import folder.

|-content
|--permissions.xml
|--repository.xml
|--roles.xml

For example look at the JahiaApp-Wiki