A container executing in the same JVM where Cargo is running


An embedded container means that Cargo is using directly the container's Java API to control it and starts the container in the same JVM as where it is running. This implies you can do many advanced things programmatically - such as playing with the class loader, adding proxy classes, etc.

Please note that if you're using one of the embedded implementation you'll need to ensure that you have the container's JARs in your classpath.

Be very careful when using embedded containers

Embedded containers, since they run in an existing JVM, will come with a large number of limitations:

  • Any existing JVM setting, such as JVM properties or debuggers, will be inherited from the parent JVM and cannot be changed.
  • Some features such as logging might not work as expected as they inherit existing Java logger settings.
  • You might very quickly run into a JAR hell. While the Cargo samples' might give you ideas on how to avoid it, this might not work in all circumstances.
  • If you are using either the Ant tasks or Maven 3 plugin, the container will most likely inherit even more "uncontrollable" items that come from these tools. You will very likely get java.lang.NoClassDefFoundError exceptions - Which typically happens when two different versions of the same JAR end up in the classpath or class loader.
  • When using embedded containers with the Maven 3 plugin:
  • Some containers contain classes that have final attributes defined on certain other classes, that remain set to their updated values even if you reset the class loader - The only way to revert this is to restart the JVM. This implies that:

    • It might not possible to execute different versions of these containers in the same JVM

    • It might also not be possible to run two embedded container instances one after the other within the same JVM but different classpaths

As a result, except in cases where you have a compelling reason to use an embedded container, please use an Installed Container instead.

Copyright 2004-2024. All rights reserved unless otherwise noted.
Click here to read our privacy and cookie policy