Don’t build Magnolia: build your projects.

This is the first of a series of posts, where I will attempt to consolidate a set of practices for creating, building and deploying Magnolia projects.

Why, you ask ?

Over time, Magnolia has grown into a fairly complex, but beautifully flexible product. There are a number of features, techniques and tricks that can make one’s life much easier. Unfortunately, I still see a lot of folks building or deploying their projects in ways that make me cringe. Not that they’re doing awful things, no, but it seems it’s high time to gather a few tricks here that will hopefully make a few folks go “aaaaahhhh”, and perhaps even a few others cursing me for not telling them about all this earlier.

I’ll introduce a few points which will hopefully make everyone’s life a little simpler, developers and sys admins alike. Here’s a little roadmap of the key points, covered by different blog posts:

  • Automate your builds: don’t build Magnolia, build your project. You’re reading this post.
  • Automate your configurations: you don’t need to manually configure Magnolia when installing it.
  • Streamline your deployments: you don’t need to modify files on the filesystem to configure Magnolia, or produce different artifacts for different instances of the same project.

Prerequisites

We’ll use the following tools:

  • Maven 2.2.1. The stuff mentioned here probably works with Maven 3, but I’ve never tried. Leave a comment if you do !
  • IntelliJ IDEA. Am I opinionated when I claim this is the best Java IDE around ? Perhaps. Again, if you’re an Eclipse, Netbeans, or any other IDE user, please leave comments if you know equivalent “procedures” for your IDE of choice.

You might be better off feeling familiar with:

  • Maven and its dependency mechanism. Similar concepts apply if you use other dependency management and build tools, such as Ant+Ivy or Gradle. I’ve been looking into writing this article with Gradle instead, but it seems it doesn’t support war overlays just yet, so I abandoned the idea. Comments, yada yada yada, you know the deal.
  • A *nix shell. I’ll use a few commands here and there, and some might be OSX-specific. Hopefully, you’ll know your way around the terminal your OS provides.

Background

Often times, I see people trying to build Magnolia itself, as the first step to build their own project. That’s quite a hurdle, I’m trying to demonstrate below that it’s not necessary. Once your project is setup, of course, you might want to make modifications to Magnolia, but you’ll find out that in most case you should be able to do everything you need within the confines of your own project.

Creating a basic, empty project

For simplicity’s sake 1, I will use Maven and its archetype mechanism in the following example. Open a terminal, cd to somewhere you feel comfortable and type the following command:

mvn archetype:generate -DarchetypeCatalog=https://nexus.magnolia-cms.com/content/groups/public/

If this is the first time you use archetypes, this might take a while. You’ll get to choose which archetype to use in a list of archetypes. If the list hasn’t changed since writing this post, 6 should be your choice. (magnolia-project-archetype)

After entering some details about your project, this archetype will create an empty, ready-to-use, Maven structure with a top-level “project” and a webapp as a Maven sub-module. This might seem overkill for a simple project, but it will ease the transition if you want to add modules later on.

For the sake of the example, here are the values I used:

'groupId': com.acme
'artifactId': acme-project
'version': 1.0-SNAPSHOT
'package': com.acme
'magnolia-version': 4.4.4
'project-name':  My ACME Project

A first build (Ô, the emotion)

Let’s enter the project we just created, and build it.

cd acme-project/
mvn clean install

Again, if this is your first time, this might take a little while, possibly longer. Go grab a coffee.

Now that we have a first successful build, let’s switch to our IDE of choice. 2

open -a "IntelliJ IDEA 10" pom.xml

If you’re not on OSX, just create a new project, based on the top-level pom.xml with File > New Project > Import project from external model > Maven > Select root directory of the project > Next > Next > Next > Finish.

Running the project

Well, hopefully you know the drill in your IDE. With IntelliJ, I do: Run > Edit Configurations > + (Tomcat > Local), then add the acme-project-webapp:war exploded artifact to the Deployment section, make sure it deploys to the root context (/)… or anywhere else, as long as you remember it, anyway.

Now hit that Start button already ! Tomcat should start Magnolia, and my IntelliJ is configured to then open my browser to http://localhost:8080 once it’s up and running. Should that not be the case for you, well, do it manually.

Go through the install screen, and once the installation is completed, login as superuser (password: superuser).

Ok, so what now ? We have a basic Magnolia project running, but … what’s next ? Well, let’s just make it a little more useful, by giving it a set of useable templates and some layout.

Adding a module… or two

So, let’s add Magnolia’s Standard Templating Kit to our webapp3. Open acme-project-webapp/pom.xml, and in the <dependencies> section, paste the following:

<dependency>
  <groupId>info.magnolia</groupId>
  <artifactId>magnolia-module-standard-templating-kit</artifactId>
  <version>1.4.4</version>
</dependency>

Note: In IntelliJ, a notification bar shows up when you modify a pom file, prompting you to “Import Changes” or “Enable Auto-Import”. Enabling auto-import works quite well, but can be resource intensive when heavily modifying pom files. For this example, you can go ahead and enable it. If you don’t, just remember to click “Import Changes” at least once before starting up the server.

At this stage, you’ll need to restart your server for the new module to be picked up, but to save you the trouble of deciphering an error message, do not start just yet. The Standard Templating Kit has a non-optional dependency to the DMS module, which we’ll need to add to our pom as well 4. So, adding the DMS module:

<dependency>
  <groupId>info.magnolia</groupId>
  <artifactId>magnolia-module-dms</artifactId>
  <version>1.5.2</version>
</dependency>

And while we’re at it, we probably want some sort of design for our project, right ? Well, why don’t we go and use a different theme than the default theme shipped with the STK bundle ? There’s a different theme available on the Magnolia Forge, let’s use that !

<dependency>
  <groupId>info.magnolia.themes.blue</groupId>
  <artifactId>magnolia-theme-blue</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

Once our beloved IDE has picked up and digested all those changes, it’s time to restart our server. By the magics of Maven, not 3, but a dozen-or-so modules will need to be installed.

An aside for Maven enthusiasts

If you’ve looked at the pom files produced by the archetype above, you’ll have noticed two things:

  • We depend on the magnolia-empty-webapp, twice. This is to compensate for MWAR-33. The one dependency to the war artifact is to overlay our project on top of it: we don’t need to have a web.xml, nor any of the other files that come with the basic Magnolia webapp. The dependency to the pom artifact is to ensure Maven can resolve dependencies properly. Finally, we need to exclude WEB-INF/lib/*.jar from the dependent war files, which is why there is a little bit of configuration for the maven-war-plugin in our webapp pom.
  • Our top-level pom has yet another “special” dependency: it depends on magnolia-project (which is the top-level pom for magnolia-core, magnolia-empty-webapp, …) in scope:import. This has a special meaning in Maven: essentially, all dependencies in the referred artifact’s <dependencyManagement> section are “imported” into our project. This is the equivalent of copy-pasting that entire section into our project, … without the copy-and-paste mess. This would be extremely advantageous, if you want to depend on, say, magnolia-enterprise-webapp in scope import: you would not need to know which version of STK was shipped with that specific release of Magnolia, nor of any other module. The day you want to move to Magnolia 4.4.5, 4.5 or 5.0, you’d only need to change that one version number, and get all upgraded dependencies. And this wouldn’t even prevent you from selecting specific versions of some modules if you’d want to. (for instance if a bug fix of the DMS module came out but you didn’t want to update all other modules). Unfortunately, up to 4.4.4, there’s a caveat, which is why we still have both the magnolia-empty-webapp:pom and magnolia-project:pom dependencies.

A first page and a bang

If you’ve been getting impatient (I don’t blame you!), you have tried to create a first page in this project, and your eyes started to bleed when you saw the infamous red-and-yellow “FreeMarker template error” – well, you’ve stumbled upon MGNLSTK-788 !

Call me a tease, but we’ll look into solving that in next installment of this series of posts.

Conclusion

In this first post, we’ve looked at how we can relatively simply create a Magnolia-based project, building with Maven. Granted, the project doesn’t do much yet, but it’s reached a few goals already:

  • We are building our own project with Magnolia. At no point in time did anyone come and manually “drop a jar” in the webapp, or modify a configuration file in the deployed webapp. We intend to keep it that way over the course of this series of post.
  • The build is reproducible. At any point from now, you should be able to commit your files to your scm, have builds produced by your team mates, your CI server, and do releases of your project.

  1. The arguable simplicity of using the tools I know best. Really looking forward for some Gradle examples. 
  2. Just for the record, I don’t ever type this; I have an alias in my ~/.profile and I just type idea pom.xml, which I find quite practical. IntelliJ also has a built-in command (File > Create Command-line Launcher) which generates a script to do the same. 
  3. This is where some Maven experience and knowledge might start to get interesting. If you’re used to Maven, you’ll probably want to add this dependency to the top-level pom’s <dependencyManagement> section, and refer to it without version number in the webapp pom. 
  4. If you wonder why it doesn’t come in transitively, it’s because of a fairly annoying “feature” of our builds: when we build a “bundle”, we use the maven-assembly-plugin to incorporate all dependencies of a project by filtering on their scope, only including those in the compile scope. In the case of the STK, we chose to mark the DMS dependency in scope:provided, because we did not want the DMS to end up in the bundle, considering that it is already shipped with the default Magnolia CE bundle. For another, perhaps more understandable example, we do the same thing with magnolia-core: we don’t want nor need to ship magnolia-core in the STK bundle. However, we do bundle STK with a couple of other less common modules: inplace-templating, resources, … Not bundling the DMS module helps folks installing manually: one can just unzip the bundle in WEB-INF/lib and not search for duplicate jars. Feedback and ideas more than welcome, of course! 

87 thoughts on “Don’t build Magnolia: build your projects.

  1. Greg, great high quality post!
    I’m glad I found out myself a good development setup for Magnolia I use the same tools except that I’m using Maven 3, which also works with the setup you described in your article.
    In addition to that I use JRebel (in IDEA) to prevent Tomcat server restarts.
    I hope the next two articles in this series will be released soon…

    • Yup, Maven 3 should be a drop-in replacement for most things. We’re still on 2.2.1 internally, which I why I mentioned it in the article.
      I’m also using JRebel now, but I figured I’d skip that for this article to avoid more confusion than necessary. Also, adding modules to a project would still require a restart anyway

      Thanks for the comment !

  2. Thanks Greg for this nice and important article! Looking forward for more

    - The dependency on magnolia-project was new to me. I will have a look at this.
    - One question: How often is the mvn archetype updated?
    - I will have a glimpse on JRebel too

    • Hey Stefan, thanks for the comment
      The dependency on magnolia-project is currently a “workaround”, really. In fact, if you depended on magnolia-empty-webapp:pom with scope:import, it would not be needed. But due to MAGNOLIA-3545, you’d run into all sorts of problem if you swapped the dependency to magnolia-enterprise-webapp. “magnolia-project” is the parent project (reactor) for magnolia-core and all base modules until magnolia-empty-webapp.
      I don’t expect the archetype to be updated very often, but if you have suggestions for improvements, feel free to add them to http://jira.magnolia-cms.com/browse/ARCH – I have to mention these (much better!) versions of the archetypes were contributed by and to the community, so cheers to Joerg, here !
      JRebel is awesome, yes

  3. Pingback: Don’t deploy Magnolia: deploy your projects. | Greg’s ramblings

  4. Hi, i tried this dependencies with eclipse, maven and glassfish, but when i enter to the website section in magnolia cms, there wasn’t any projects like it shows in other configuration, like the stk bundle that has two projects already install. Another thing is that when you create a page, this page show’s the red and yellow error of freemarker. Any ideas how to get this fixed?

    • Luis,

      That is one the purposes of this article. The 2 projects you see elsewhere (i.e on http://demoauthor.magnolia-cms.com) are demonstration projects, they come with the magnolia-demo-project (from Standard Templating Kit), which we have intentionally avoided here, since we are working towards building an actual production project, not a demo.

      As for the red-and-yellow FreeMarker error, as mentioned towards the end of the article, this is also “intentional”, and the follow-up article shows how to fix it.

  5. I couldn’t install modules. After adding the dependencies, I ran mvn install (windows xp, maven3) and restarted the server. It took me to update screen. During update, I got the following error:

    Magnolia DMS Module (version 1.5.2)
    Error while installing or updating dms module. Task ‘Bootstrap samples’ failed. (IOException: The system cannot find the path specified)

    General message
    Could not perform installation: Error importing dms.openwfe: error while processing property value

    I updated pom.xml files with the following versions:

    magnolia – 4.4.5
    stk – 1.4.5

    I’d appreciate any insight. Thanks!

  6. Pingback: Don’t deploy Magnolia: deploy your project. | Greg’s ramblings

  7. Hi Grég, just few links for those who wants to run this tutorial on Ubuntu (11.10) or/and are new to IntelliJ Idea:

    Oracle Java in Ubuntu (IntelliJ Idea requires it) http://www.webupd8.org/2011/09/how-to-install-oracle-java-7-jdk-in.html
    Installing IntelliJ Idea on Ubuntu: http://techbrew.net/articles/200711/how-to-put-intellij-idea-on-ubuntu/
    Environment variables in Ubuntu (IntelliJ Idea requires JDK_HOME or JAVA_HOME set): https://help.ubuntu.com/community/EnvironmentVariables
    How to map Eclipse concepts to IntelliJ Idea concepts: http://www.jetbrains.com/idea/documentation/migration_faq.html
    Running Tomcat on IntelliJ Idea: http://knol.google.com/k/hossein-akhlaghpour/how-to-start-debug-tomcat-or-jboss-in/1flc79hj2cw6y/21#

    • Indeed, that project hasn’t seen activity in a while, so the repository manager pruned old snapshots. Just rebuild it, so it should be back by now. Thanks for the heads up !

  8. Pingback: Spring context configuration in Magnolia « Orange11 Blog / Orange11: Enterprise Java, Open Source, software solutions, Amsterdam

  9. Can you please make an exampe if you need to add a dependency with a new module. Adding a dependency to a magnolia module is clear, less clear is how to add a new custom module

    • Hey Federico,

      I’m not sure what the difference is between the two cases that you’re mentioning. If you have a custom module that you need included in your web-app, you’ll want to add a maven dependency in the web-app’s pom.xml which points to your module. If you need to add a dependency from your module to another module (for example an extension to the dms module is likely to need a dependency to dms), you’ll need to declare that dependency in your module’s pom.xml (for building) and in your module descriptor xml (so that Magnolia’s module mechanism knows it also needs dms, and to start the modules in the correct order). Does that answer your question ?

      • Hi Gregor,

        the problem is that I didn’t know Maven before Magnolia, so I have difficulties with dependencies. I’ve made the example with the archetype, but I have problems when I try to add a new custom module. I do not have a Maven repository for, I’m trying to make a “company” pom, then a “project” pom and below a pom for the webapp, a pom for a theme module, etc…

  10. Hi!
    I get stuck right at the beginning under “Running the project”. I followed your instructions exactly, with the difference that I use Eclipse and “Import -> Maven\Existing Maven Projects” when “switching over to the IDE”.
    The Tomcat server starts up allright, but Magnolia does not get loaded. It starts in 2 seconds without any of the Magnolia info in the console. So I get a HTTP 404 error (The requested resource is not available) when trying to open the magnolia web page where I deployed it (tried root and /acme-project-webapp).

    I have previously checked out the magnolia-empty-webapp for magnolia 4.5.2 from svn and started it on the same Tomcat server I have configured in Eclipse without any problems. I guess that is the same thing as I am doing here, but in another way…

    Any ideas where I could start looking to get it to work?
    Regards, Jeremia

    • Hmm… if it starts that fast, it’s probably failing early. In some cases or on some platforms, Tomcat logs are not always redirected to the console properly, especially when it comes to startup exceptions. Have a look in #tomcat-home#/logs/catalina.#timestamp#.

      • No log files are created when I run Tomcat from Eclipse. The logs are outputted to the console, so I guess that is why no log files are created. Here is a log (copied from Eclipse):
        ——————————–
        2012-okt-01 10:15:43 org.apache.catalina.core.AprLifecycleListener init
        INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_35\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\ImageMagick-6.7.9-Q16;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;c:\Program Files\Microsoft SQL Server\110\DTS\Binn\;c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files\Java\jdk1.6.0_35\bin;C:\Program Files (x86)\Subversion\bin;C:\Program Files\Apache Software Foundation\apache-maven-2.2.1\bin;C:\Program Files (x86)\Git\cmd;.
        2012-okt-01 10:15:43 org.apache.tomcat.util.digester.SetPropertiesRule begin
        VARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:acme-project-webapp’ did not find a matching property.
        2012-okt-01 10:15:43 org.apache.tomcat.util.digester.SetPropertiesRule begin
        VARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context/Loader} Setting property ‘useSystemClassLoaderAsParent’ to ‘false’ did not find a matching property.
        2012-okt-01 10:15:43 org.apache.coyote.AbstractProtocol init
        INFO: Initializing ProtocolHandler ["http-bio-8080"]
        2012-okt-01 10:15:43 org.apache.coyote.AbstractProtocol init
        INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
        2012-okt-01 10:15:43 org.apache.catalina.startup.Catalina load
        INFO: Initialization processed in 600 ms
        2012-okt-01 10:15:44 org.apache.catalina.core.StandardService startInternal
        INFO: Starting service Catalina
        2012-okt-01 10:15:44 org.apache.catalina.core.StandardEngine startInternal
        INFO: Starting Servlet Engine: Apache Tomcat/7.0.30
        2012-okt-01 10:15:45 org.apache.coyote.AbstractProtocol start
        INFO: Starting ProtocolHandler ["http-bio-8080"]
        2012-okt-01 10:15:45 org.apache.coyote.AbstractProtocol start
        INFO: Starting ProtocolHandler ["ajp-bio-8009"]
        2012-okt-01 10:15:45 org.apache.catalina.startup.Catalina start
        INFO: Server startup in 1642 ms
        ——————————–

        • Darn. My previous got mangled. Have a look in #tomcat-home#/logs/catalina.#timestamp#.
          Now from this output, it just looks like Eclipse/Tomcat is not starting *any* webapp. Now if we could avoid turning this thread into an Eclipse problem-solving discussion…

          • I could solve the same Problem with the following I found on this side:
            http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

            Eclipse forgets to copy the default apps (ROOT, examples, etc.) when it creates a Tomcat folder inside the Eclipse workspace. Go to C:\apache-tomcat-7.0.34\webapps, R-click on the ROOT folder and copy it. Then go to your Eclipse workspace, go to the .metadata folder, and search for “wtpwebapps”. You should find something like your-eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps (or …/tmp1/wtpwebapps if you already had another server registered in Eclipse). Go to the wtpwebapps folder, R-click, and paste ROOT (say “yes” if asked if you want to merge/replace folders/files). Then reload http://localhost/ to see the Tomcat welcome page.

    • Andrew, 5.0 isn’t released yet !
      The latest version if 5.0-prev1-rc1; be aware that some artifact or group ids might have changed. Try the forum/user-list for up-to-date information.

  11. Hi there!

    I’ve a problem with my magnolia-empty-webapp.

    I create my own configuration under -wepapp -> overlays -> info.magnolia.magnolia-empty-webapp-4.5.3 -> WEB-INF -> config -> MyNewWarNameConfig

    But i.e. a checkout (other machine) or reimport of my web app pom kills my config and recreates the default ones …

    If i uncomment magnolia-empty-webapp – war no recreation, so it depends on this artifact …

    What I’ doing wrong? Should i create my own overlay? And how?

    info.magnolia
    magnolia-empty-webapp
    pom
    4.5.3

    info.magnolia
    magnolia-empty-webapp
    war
    4.5.3

    I’m using IntelliJ 11.1

    Thank you for your help!
    Klaus

    • I’m not sure what you’re trying to do in overlays. You shouldn’t have to touch that; I’m not sure even sure which of IntelliJ or Maven creates those directories.
      If you need to replace some of the files from magnolia-empty-webapp, just add those under src/main/webapp of your own webapp.

  12. Dude,

    All the endless suffering I’ve gone through to try and compile and debug Magnolia — it’s humiliating. …and surprising that my manager hasn’t fired me for outrageously gross incompetence. Started from the top here and the only glitch I ran into was trying to use the (non-tomcatable) community edition of intellij. Hope reincarnation is real so you can cash in all the Karma you’ve earned with this post.

  13. Hi, Thanks for writing the article! I am having trouble even creating the project. When I try and generate the project I get the following error no matter which option I choose (I get 4 options)

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2
    .2:generate (default-cli) on project standalone-pom: The desired archetype does
    not exist (info.magnolia.maven.archetypes:magnolia-module-archetype:1.1.0-SNAPSH
    OT) -> [Help 1]

    I have been through the Maven setup instructions here http://documentation.magnolia-cms.com/developing/dev-environment/maven/maven-init.html hoping it would help but I still get the same error. Do you have any suggestions? Many thanks!

    • Hey Steve,

      Having only 4 options is correct – did some cleanup on the repository. However, I still works for me, both with Maven 2.2.1 and 3.0.4. Which version of Maven are you using ?

      • Thanks for the reply, and sorry for my slow response (new job and been flat out). I am using Maven 3.0.4. I am not sure why it can present me with the options but then not find any of the options. I tried all 4 options and all failed with the above exception.

      • I had the same problem. The issue was that my company has a mirror configured in settings.xml. Removing that got around the issue.

  14. hallo,
    in the section “add module …” you talk about dependencies. I have found two place in pom.xml:
    - dependencies (in root of xml file)
    - dependencies in the dependencyManagement.

    what place is correct ?
    thanks

    • It depends I’m not sure what section you’re referring to. Either section have a different meaning and effect, in Maven. The first actually declares a dependency, the second allows to manage (eh) other dependencies that come in your project transitively, i.e ensuring a particular version number, for example.

  15. Hi Greg,

    Thanks for this write-up, I have been trying to get this working with release 4.5.7

    Everything seems to go ok but once I login I get a 404 when hitting admincentral. Dont see any errors anywhere… thoughts ?

    Thanks,
    Serge

    • Hard to say without seeing your logs or even what URL you’re trying to hit. Did you get the project to run with 4.4.x before ? (not that it’d be mandatory, but that would eliminate 80% of possible issues, the 20 remaining ones would be some configuration and some dependency management issues that I think have been covered in other comments)

    • I’m also trying to run 4.5.7 and receive a 404 on startup. I don’t know if you are getting the same error I was; in my case the following error was reported in the logs:

      ERROR .objectfactory.guice.GuiceComponentProviderBuilder: Magnolia failed to load module configuration. Please ensure you don’t have any legacy modules present in your web application.

      Followed by numerous SEVERE errors and stack traces. In my case this was caused by the fact that the versions of the STK or dms dependencies were not compatible with 4.5.7. The following should work:

      <dependency>
      <groupId>info.magnolia</groupId>
      <artifactId>magnolia-module-standard-templating-kit</artifactId>
      <version>2.0.8</version>
      </dependency>
      <dependency>
      <groupId>info.magnolia</groupId>
      <artifactId>magnolia-module-dms</artifactId>
      <version>1.6.5</version>
      </dependency>

    • Depends when you want to go in production, as well as how much and what kind of customization you’re going to do.

  16. I case anybody is a maven command line junky like me, inserting the following into the build/plugins section of the webapp projects pom.xml file will allow you to start the project with tomcat from the command line like so:

    $ mvn cargo:start

    Note that this requires that you set the property tomcat7.home in the properties section of your settings.xml file, otherwise you can just replace the reference to ${tomcat7.home} in the below snippet with the path to your tomcat7 installation.

    org.codehaus.cargo
    cargo-maven2-plugin
    1.1.1

    true

    tomcat7x
    ${tomcat7.home}
    180000

    target/tomcat7x

    -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n -Xmx1024m

    target/${project.artifactId}-${project.version}.war
    http://localhost:8080/

    start-container
    pre-integration-test

    start

    stop-container
    post-integration-test

    stop

  17. Looks like the xml in my comment was eaten, so:

    <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.1.1</version>
    <configuration>
    <wait>true</wait>
    <container>
    <containerId>tomcat7x</containerId>
    <home>${tomcat7.home}</home>
    <timeout>180000</timeout>
    <systemProperties />
    <dependencies />
    </container>
    <configuration>
    <home>target/tomcat7x</home>
    <properties>
    <cargo.jvmargs>-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n -Xmx1024m</cargo.jvmargs>
    </properties>
    <deployables>
    <deployable>
    <location>target/${project.artifactId}-${project.version}.war</location>
    <pingURL>http://localhost:8080/</pingURL&gt;
    <properties>
    <context></context>
    </properties>
    </deployable>
    </deployables>
    </configuration>
    </configuration>
    <executions>
    <execution>
    <id>start-container</id>
    <phase>pre-integration-test</phase>
    <goals>
    <goal>start</goal>
    </goals>
    </execution>
    <execution>
    <id>stop-container</id>
    <phase>post-integration-test</phase>
    <goals>
    <goal>stop</goal>
    </goals>
    </execution>
    </executions>
    </plugin>

  18. I also had a problem of getting the project to run in eclipse like Jeremia Mörling but I found out that it was actually the problem with the way I had tomcat configured in Eclipse. make sure you DON’T have the “serve modules without publishing” option checked off in eclipse. That resolved it for me.

  19. Hi Greg, thx for these posts, they seem like a great starting place.

    I’ve come a little stuck with blue theme. It looks as though this is missing from the repo again.

    Also, is this tutorial still fully applicable to version 5 of Magnolia, or are there key differences which might cause complications?

    Thanks

    • Hey Sheldon,

      Thanks for the comment. I used blue theme as an example because it was something simple enough to get started without having to care about all sorts of side issues, while not being something that’s already built in. I just triggered a build for it, so it should be available again.
      As for Magnolia 5 – it’s all in big part still valid. The main thing that’s changed is that MAGNOLIA-3545 and associated issues have been fixed (gradually, so get 5.2 for the latest and greatest), and that we changed the groupId for magnolia-bundled-webapp to info.magnolia.bundle (and info.magnolia.eebundle for the enterprise webapp).

  20. Hello Greg,

    great posts, thanks for them! I am just setting up my magnolia project (intellij idea 13, M5, tomcat) and it works great, just when I add new depedency to my pom.xml (such as STK module) and restart the server, this module doesn’t get added to my Magnolia app. After a while I realized that for the changes in pom.xml to work I have to run “mvn clean install” in project direcotry. Or did I miss some settings in IDE that will do this automatically after importing maven changes?

    • Sorry for another post, but realized that even after doing “mvn clean install”, modules doesnt get added to my webapp. Update was requested on startup, everything went well, but when I magnolia starts up, new modules are not there (no stk menu in app launcher and it’s not in configuration/modules).
      Thanks for the answer!

        • Hey Petr, no worries, glad you figured it out ! In general, I’d recommend setting up a dependencyManagement section in your parent pom, and the actual dependency in the webapp; in that case you don’t have to specify the version number anymore, so all version numbers are centralized in the root pom.
          Cheers !

  21. Hi Thanks for detailed post. I could build war file and deployed on tomcat 7.0.47. When I browse http://localhost:8080/myapp I could see installation page. When I started installation, I am getting the following errors.
    Please advice what went wrong.

    Thanks
    Lalith

    Magnolia Admin Interface Legacy Module (version 5.0.2)
    Could not install or update adminInterface module. Task ‘Legacy app’ failed. (PathNotFoundException: /modules/ui-framework/config)

    Magnolia Cache Module (version 5.2.0)
    Could not install or update cache module. Task ‘Legacy app’ failed. (PathNotFoundException: /modules/ui-framework/config)

    Magnolia DAM Module (version 1.1.0)
    Error while installing or updating dam module. Task ‘Configure the push policy for dam workspace’ failed. (NullPointerException: )

    General messages
    Could not perform installation: null

    • Hi there,

      This looks like a mixture of a wrong mix of dependencies (or some missing one) with mistakes on our end (some modules should apparently have a dependency on ui-framework and don’t).

      This article needs an update, because some of the issues it works around are now fixed; in the meantime, check our forum for similar issues – there are couple – if you can’t find them, get back to me, or post your pom.xml on the forum and I’ll have a look.

      • Thanks for the suggestion. I browsed forum and found the fix. Adding the following dependencies did the trick.

        info.magnolia.ui
        magnolia-ui-framework
        5.2

        info.magnolia
        magnolia-module-legacy-admininterface
        5.2

        I detailed the steps with eclipse at http://lalith-sharan-magnolia.blogspot.in/2014/02/build-magnolia-project.html.

        forum link: http://forum.magnolia-cms.com/forum/thread.html?threadId=3f466009-9d53-4b7d-96cf-e3ecad87be97#77186abb-d19a-48f6-a0df-0698602db4fb

        • I could build with 5.2.2 and deploy on tomcat 7. But when I start installing modules, nothing is happening after 160/288. How to debug further and fix the problem?

          Tomcat trace is as below
          2014-02-26 16:37:44,907 WARN info.magnolia.importexport.BootstrapUtil : Deleted already existing node for bootstrapping: /server/filters/securityCallback/clientCallbacks/form
          2014-02-26 16:37:44,940 WARN info.magnolia.importexport.BootstrapUtil : Deleted already existing node for bootstrapping: /modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps/configuration
          2014-02-26 16:37:44,913 INFO fo.magnolia.objectfactory.ObservedComponentFactory: Re-loaded info.magnolia.freemarker.FreemarkerConfig from /server/rendering/freemarker
          2014-02-26 16:37:45,257 WARN info.magnolia.module.InstallContextImpl : > Property “pattern” was expected to exist at /server/filters/uriSecurity/bypasses/login with value “/.resources/loginForm” but has the value “/.resources/defaultLoginForm” instead.
          2014-02-26 16:37:45,808 WARN info.magnolia.importexport.BootstrapUtil : Deleted already existing node for bootstrapping: /server/i18n/authoring
          2014-02-26 16:37:45,850 ERROR info.magnolia.module.InstallContextImpl : > Error while installing or updating adminInterface module
          . Task ‘Bootstrap’ failed. (ItemExistsException: a node with uuid 1912ce6d-66f5-415a-9be4-9cf02876df14 already exists!)
          java.lang.RuntimeException: Error importing config.server.i18n.authoringLegacy: a node with uuid 1912ce6d-66f5-415a-9be4-9cf02876df14 already exists!
          ………
          2014-02-26 16:37:45,933 ERROR info.magnolia.module.ui.ModuleManagerWebUI : Could not perform installation: Error importing config.server.i18n.authoringLegacy: a node with uuid 1912ce6d-66f5-415a-9be4-9cf02876df14 already exists!
          java.lang.RuntimeException: Error importing config.server.i18n.authoringLegacy: a node with uuid 1912ce6d-66f5-415a-9be4-9cf02876df14 already exists!
          ………….
          2014-02-26 16:37:46,018 ERROR info.magnolia.module.InstallContextImpl : > Could not perform installation: Error importing config.server.i18n.authoringLegacy: a node with uuid 1912ce6d-66f5-415a-9be4-9cf02876df14 already exists!
          java.lang.RuntimeException: Error importing config.server.i18n.authoringLegacy: a node with uuid 1912ce6d-66f5-415a-9be4-9cf02876df14 already exists!
          ……………..
          2014-02-26 16:37:46,713 INFO fo.magnolia.objectfactory.ObservedComponentFactory: Re-loaded info.magnolia.cms.exchange.ActivationManager from /server/activation

          Thanks
          Lalith

          • Check your WEB-INF/lib folder for duplicates jars (same name, different version number) and try again with a clean repository.

  22. Hi,
    I verified there are no duplicates in WEB-INF/lib. Now I deleted .m2/repository and started mvn clean install. Dependency download is in progress. Let me check after completing the repository sync.

    Thanks
    Lalith

    • Oh wow, that’ll take a while; I meant a clean *JackRabbit* repo, not Maven’s. (by default it’s the “repositories” folder inside your webapp folder, but you might have configured it to be outside of the webapp if you followed all instructions in this blog:))

  23. Hi,
    Thanks for quick update. I tried with clean jackrabbit repository and also clean maven repository, but no luck. I am consistently encountering same issue. Magnolia Installation page showing following errors. The error says – Task ‘Bootstrap’ failed.

    Magnolia Admin Interface Legacy Module (version 5.2.2)
    Error while installing or updating adminInterface module. Task ‘Bootstrap’ failed. (ItemExistsException: a node with uuid 1912ce6d-66f5-415a-9be4-9cf02876df14 already exists!)

    General messages
    Could not perform installation: Error importing config.server.i18n.authoringLegacy: a node with uuid 1912ce6d-66f5-415a-9be4-9cf02876df14 already exists!

    Thanks
    Lalith

  24. Hi,
    Thanks a lot for your support. Finally I could succeed with the following dependencies pom as suggested by Peter Phillips on http://forum.magnolia-cms.com/.

    Thanks
    Lalith

    info.magnolia
    magnolia-module-legacy-admininterface
    5.2.2

    info.magnolia
    magnolia-module-standard-templating-kit
    2.7.2
    jar

    info.magnolia.dam
    magnolia-dam
    1.2.2

    info.magnolia
    magnolia-module-form
    2.2.2

    info.magnolia
    magnolia-theme-pop
    2.7.2

    info.magnolia.themes.blue
    magnolia-theme-blue
    1.0.0-SNAPSHOT

  25. Hi Greg!

    How are you doing? First of all thanks for this great post

    We’ve been developping with Magnolia for 3 years now, lately I got to use it a bit more once again, and I’m a bit confused with overlays and target.
    I’m pretty sure that the last time I used intellij Idea and Magnolia, the repository was created in the enterprise webapp overlays (and I made configuration changes in the web.xml of the overlays). Now, no matter what configuration I try, it always seems to run the war that is created in the target folder instead of the overlays. I tried building a project from scratch with the archetypes and it did the same, Idea wants to run the webapp of the target folder, not the overlays one.
    Is it and IDE misconfiguration, or something changed in the way that Idea runs the webapp:exploded artifact? I’m using the latest version (13). Thanks!

    • I don’t know of anything that changed in either products or your project, but the way it behaves *now* (i.e deploy the webapp of target/) is the correct way. The stuff IntelliJ has in overlays/ is AFAIK just work folders where it extracts the webapps that are “under” the final (target/) one.

      • What I don’t understand is that it seems that Idea doesn’t link to the modules anymore, it takes the .jar of the WEB-INF/lib existing in the target folder, so I’m forced to do a clean install every time I change a module … something must be wrong with our .pom configuration

        • Delete your whole IntelliJ project (delete .idea and *.iml everywhere), and recreate it by importing the pom.xml. That’s how I’d do it. If something’s still wrong, then yeah, most likely it’s because your pom.xml has issues. Fix them, rince and repeat (no need to recreate every time, the re-import feature works well)

  26. hi, Greg
    Thanks for your nice post
    but i have some troubles after log in page, i got this :

    The server has encountered an internal error.

    We apologize for any inconvenience caused.

    If you keep experiencing difficulties, please contact your system administrator.
    Make sure you send along the stack trace below.

    javax.servlet.ServletException: com.vaadin.server.ServiceException: info.magnolia.objectfactory.MgnlInstantiationException: java.lang.reflect.InvocationTargetException
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:240)
    at info.magnolia.ui.admincentral.AdmincentralVaadinServlet.service(AdmincentralVaadinServlet.java:131)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at info.magnolia.cms.filters.ServletDispatchingFilter.doFilter(ServletDispatchingFilter.java:129)
    at info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
    at info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
    at info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
    at info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
    at info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
    at info.magnolia.cms.filters.CompositeFilter.doFilter(CompositeFilter.java:67)

    thanks for advanced

    • Hard to say. Probably a dependency mismatch. This post was written in pre-5.0 times Check your WEB-INF/lib for duplicate or different versions of jars, and check the log files for more complete stacktraces.

  27. Hi, Greg
    First, I’m a Chinese and have a pool English.So please forgive my words which maybe so strange.
    I touched magnolia cms,an amazing open source cms in my mind, days ago .I get the bundle version and have it running well. I test the demo-project,and can publish the author-instance to public-instance. I study magnolia’s academy for servial days, but already don’t know how to create a public instance by myself.
    After this article, I have get a magnolia project in your way(my IDE is myeclipse),and now I want to have a public-instance named myFirstProject,when I named is as magnoliaPublic , and then go to address http://localhost:8080/magnoliaPublic , it can auto run demo-project’s home page well,
    but if I named my public-instance as “myFirstProject”,when I restart server and install any modules, I go to the page which as same as my author-instance.
    I want to create a customized public instance ,how can I do ??

    I your this article , you haven’t a public-instance , and have no project in pages app .

    My step is :
    1. create magnolia in my IDE as same as your this article.(My magnolia version is 5.2 ),I named the project as “magnoliaAuthor”
    2.(Skip my way of mvn clean install ),I get the war under tomcat’s webapp
    3.run tomcat , and go to http://localhost:8080/magnoliaAuthor
    4.Installed modules , and it runs well
    5. But when I go to pages app , and add a page, and action the button “publish”,it occur an error, means cannot find the public-instance of localhost:8080/myFirstProject(Before this , I changed the value of URL to “localhost:8080/myFirstProject”,which is the property of magnoliaPublic8080 (Configuration –>server–>activation–>subscribers–>magnoliaPublic8080 )

    6. Okay,I know , I haven’t public-instance project of “myFirstProject”,Now
    My mean is to create a public-instance named myFirstProject

    7. I follow the bundle version (bundle with tomcat 7 ),under tomcat 7′s folder of bin/magnolia_control.sh, I copy from my author-instance ,and this is my shell:

    4 magnoliaAuth=”magnoliaAuth”
    5
    6 echo “Please input a name for your public instance :”
    7 read magnoliaPublic
    8
    9 if [ ! -d "$magnoliaPublic" ];
    10 then
    11 mkdir “$magnoliaPublic”
    12 fi
    13
    14 if [ "$1"x = "-v"x ]
    15 then
    16 cp -r -v $magnoliaAuth/WEB-INF $magnoliaPublic/
    17 cp -r -v $magnoliaAuth/META-INF $magnoliaPublic/
    18 cp -r -v $magnoliaAuth/docroot $magnoliaPublic/
    19 else
    20 cp -r $magnoliaAuth/WEB-INF $magnoliaPublic/
    21 cp -r $magnoliaAuth/META-INF $magnoliaPublic/
    22 cp -r $magnoliaAuth/docroot $magnoliaPublic/
    23 fi

    8.Then I got the project of myFirstProject ,restart tomcat server

    9. I want to go to page localhost:8080/myFirstProject/demo-project,But I cannot do this.When I go to the url, I’ll be redirect to myFirstProject’s login page.(The same way ,If I named the project as magnoliaPublic,my expection will work.So I guess if anywhere need to configuration?)

    10.I tried to change my myFirstProject from author-instance to public-instance ,but I failed .When I changed my roles of anonymous,I get an error says:”have no such workspace ”

    Thanks for your read,I’ll wait for your replay all time.Very very thanks O(∩_∩)O ~…

      • Hi Grégory
        Thanks for your reply,and I have setted up my another public-instance named firstProject.Thanks for your help ,this runs will. Means now , I have a author instance named “magnolia-new”, and tow public-instance named “magnoliaPublic” and “firstProject” .
        But when I configured my Configuration –>server–>activation–>subscribers–>magnoliaPublic8080 ,URL is http://localhost:8080/magnoliaPublic ,
        I dublicated another public-instance named magnoliaPublic8081,URL is http://localhost:8080/firstProject.
        and my author-instance open pages app , have an demo-project pages(firstProject is as same as magnoliaPublic). When I modified demo-project such as change navigate title from “Home” to “Website”,and click button publish .And then I go to url localhost:8080/magnoliaPublic/demo-project, It changes correct. I go to url localhost:8080/firstProject/demo-project ,it did’t change . So ,I’m uncertain ,How my author-instance(Mine named magnolia-new ) know which public instance to publish?Are there somewhere to configure? I find many academy of magnolia academy ,but haven’t fund what can solve my problem.
        Thanks for your replay O(∩_∩)O~~~~~

  28. Hi Greg
    Whenever I start a new project I come to this blog page to copy&paste the archetype command
    However now that Magnolia’s Nexus will only be accessible hover https in the very near future please update the archetype command in your article correspondingly! Thanks!
    Cheers, Will

  29. Hi Greg, I found this post really helpful but I’d like to go a bit further trying to create an app. What’s the optimal intelliJ configuration for doing this? I already got the app-tutorial from git and I’d like to create the jar file to put it in the webapps folder.

  30. The options have changed, if you want to update your post i think the one you are aiming for is option 5.

    Choose archetype:
    1: https://nexus.magnolia-cms.com/content/groups/public/ -> info.magnolia.maven.archetypes:magnolia-module-archetype (An archetype to create basic Magnolia modules)
    2: https://nexus.magnolia-cms.com/content/groups/public/ -> info.magnolia.maven.archetypes:magnolia-forge-module-archetype (An archetype to create a Magnolia module to be hosted on the Magnolia Forge)
    3: https://nexus.magnolia-cms.com/content/groups/public/ -> info.magnolia.maven.archetypes:magnolia-blossom-module-archetype (An archetype to create Magnolia modules using Blossom)
    4: https://nexus.magnolia-cms.com/content/groups/public/ -> info.magnolia.maven.archetypes:magnolia-theme-archetype (An archetype to create STK Theme modules)
    5: https://nexus.magnolia-cms.com/content/groups/public/ -> info.magnolia.maven.archetypes:magnolia-project-archetype (An archetype to create a Magnolia project (a parent pom and a webapp))

  31. i developed my customized magnolia by using maven. i am creating war everytime i created my own template modules. after every build, it is loosing its database. how to resolve this. could you please help me out.

    regards,
    suneel

  32. I using maven project, when I deploy the project (mvn clean install) the jar is updated, but the magnolia cms instance is empty without content loaded previously, could you help me to solve this problem?
    I need deploy without export and import content in mangolia cms instance using maven project.

  33. Pingback: » Magnolia – A First Project

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>