[[GuiceMavenPlugin-GuiceMavenPlugin]]
=== Guice Maven Plugin

The Guice Maven Plugin allows you to run your
link:enterprise-integration-patterns.adoc[Enterprise Integration
Patterns] using link:guice.adoc[Guice] for
link:dependency-injection.adoc[Dependency Injection] inside Maven along
with being able to support link:visualisation.adoc[Visualisation] along
with integration of the link:visualisation.adoc[Visualisation] diagrams
into the standard maven reports for your project.


[[GuiceMavenPlugin-GoalsSupported]]
==== Goals Supported

[width="100%",cols="34%,66%",options="header",]
|=======================================================================
|Goal |Description
|link:guice-run-maven-goal.adoc[guice:run]
|Boots up Camel in the context of a separately initiated Java thread
using the link:guice.adoc[Guice] configuration in the `jndi.properties`
file on the classpath and runs your routing rules

|link:guice-embedded-maven-goal.adoc[guice:embedded]
|Boots up Camel using the link:guice.adoc[Guice] configuration at
`jndi.properties` on the classpath and runs your routing rules

|link:guice-dot-maven-goal.adoc[guice:dot]
|Generates DOT files and then HTML, PNG, SVG files for your EIP routing
rules with integration into Maven Reports
|=======================================================================

[[GuiceMavenPlugin-Addingtheplugintoyourpom.xml]]
==== Adding the plugin to your pom.xml

Add the following in your `<build><plugins>` section

[source,xml]
----
<plugin>
  <groupId>org.apache.camel</groupId>
  <artifactId>guice-maven-plugin</artifactId>
</plugin>
----

You can also specify what Main class to use when running the plugin. By
default this is `org.apache.camel.guice.Main`.

[source,xml]
----
<plugin>
  <groupId>org.apache.camel</groupId>
  <artifactId>guice-maven-plugin</artifactId>
  <!-- optional, default value: org.apache.camel.guice.Main -->
  <configuration>
    <mainClass>mypackage.boot.camel.CamelStartup</mainClass>
  </configuration>
</plugin>
----

[[GuiceMavenPlugin-MakinguseofanoptionalJNDIpropertiesfile]]
==== Making use of an optional JNDI properties file

*Available as of Camel 2.13.0*

Optionally if the name of your JNDI properties file is something else
other than the default `jndi.properties` or if it's not on the default
classpath, then you can make use of the `jndiProperties` option as shown
below:

[source,xml]
----
<plugin>
  <groupId>org.apache.camel</groupId>
  <artifactId>guice-maven-plugin</artifactId>
  <configuration>
    <jndiProperties>/path/to/my/jndi/properties/my-guice-jndi.properties</jndiProperties>
  </configuration>
</plugin>
----


[[GuiceMavenPlugin-Classpath]]
==== Classpath

The plugin will construct a classpath of any Maven dependency with scope
`compile`. The classpath is output as an `INFO` log statement upon
startup.


[[GuiceMavenPlugin-RouteInformation]]
==== Route Information

Information about the generated routes is available through the GraphViz
report, and also through the log statements generated by the run goal.
If you would like to see this information then add a log4j (or other
commons-logging implementation) config file with the following levels.

===== src/main/resources/log4.properties

[source,java]
----
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.logger.org.apache.camel.impl.DefaultCamelContext=DEBUG, stdout
log4j.additivity.org.apache.camel.impl.DefaultCamelContext=false
----

This should produce a log statement similar to:

....
670  [org.apache.camel.guice.Main.main()] DEBUG org.apache.camel.impl.DefaultCamelContext - Adding routes from: Routes: [Route[ [From[jms:queue:queueA]] -> [To[jms:queue:queueB], To[jms:queue:queueC]]]] routes: []
....


[[GuiceMavenPlugin-IntegrationintoMavenReports]]
==== Integration into Maven Reports

If you add the guice-maven-plugin to your `<reporting>` section of your
pom you will automatically get the
link:visualisation.adoc[Visualisation] reporting generated for your
project as part of the regular maven site generation.

For example add the following into your pom:

[source,xml]
----
<project>
  ...
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>guice-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </reporting>  
</project>
----

Then when you run:

....
mvn site
....

Your context will be booted up via the `jndi.properties` files, the DOT
file generated and a nice HTML report created.

===== GraphViz DOT required

Note to get the nice HTML, PNG and SVG outputs from the DOT files you
will need to install the http://graphviz.org[GraphViz] DOT executable
and add it to your PATH so that the plugin can invoke DOT to generate
the PNG/SVG files.

For more details see the link:camel-dot-maven-goal.adoc[guice:dot].
