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=http://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! 

52 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.

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>