Quando se executa um teste JBehave, surge o seguinte erro:
java.lang.NoClassDefFoundError: org/apache/log4j/Priority
ou
java.lang.NoClassDefFoundError: Could not initialize class freemarker.template.Configuration
A solução é bastante simples: Adiciona no pom.xml a dependência para o
log4j.
<plugin>
<groupid>org.jbehave</groupid>
<artifactid>jbehave-maven-plugin</artifactid>
<version>${jbehave.core.version}</version>
<configuration>
...
</configuration>
<executions>
... </executions>
<dependencies>
<dependency>
<groupid>log4j</groupid>
<artifactid>log4j</artifactid>
<version>1.2.17</version>
</dependency>
</dependencies>
</plugin>
E o problema fica resolvido.
Exemplo de um stacktrace mais completo com o problema:
[WARNING] Failed to run embeddable XptoStories
java.lang.NoClassDefFoundError: org/apache/log4j/Priority
at freemarker.log._Log4JLoggerFactory.getLogger(_Log4JLoggerFactory.java:67)
at freemarker.log.Logger.getLogger(Logger.java:284)
at freemarker.template.utility.SecurityUtilities.
(SecurityUtilities.java:66)
at freemarker.ext.beans.BeansWrapper.(BeansWrapper.java:147)
at freemarker.template.ObjectWrapper.(ObjectWrapper.java:81)
at freemarker.core.Configurable.(Configurable.java:161)
at freemarker.template.Configuration.(Configuration.java:195)
at freemarker.template.Configuration.(Configuration.java:172)
at org.jbehave.core.reporters.FreemarkerProcessor.configuration(FreemarkerProcessor.java:30)
at org.jbehave.core.reporters.FreemarkerProcessor.process(FreemarkerProcessor.java:21)
at org.jbehave.core.reporters.TemplateableViewGenerator.write(TemplateableViewGenerator.java:270)
at org.jbehave.core.reporters.TemplateableViewGenerator.createReports(TemplateableViewGenerator.java:222)
at org.jbehave.core.reporters.TemplateableViewGenerator.generateReportsView(TemplateableViewGenerator.java:112)
at org.jbehave.core.embedder.Embedder.generateReportsView(Embedder.java:256)
at org.jbehave.core.embedder.Embedder.generateReportsView(Embedder.java:244)
at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:220)
at ...
at org.jbehave.core.embedder.Embedder.runAsEmbeddables(Embedder.java:128)
at org.jbehave.mojo.RunStoriesAsEmbeddables.execute(RunStoriesAsEmbeddables.java:18)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:242)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
... 40 more