Fitnesse Maven 类路径错误
Posted
技术标签:
【中文标题】Fitnesse Maven 类路径错误【英文标题】:Fitnesse Maven Classpath error 【发布时间】:2018-03-27 17:19:25 【问题描述】:我正在尝试在我当前的项目中设置 Fitnesse。
pom.xml 配置有:
<!-- https://mvnrepository.com/artifact/org.fitnesse/fitnesse -->
<dependency>
<groupId>org.fitnesse</groupId>
<artifactId>fitnesse</artifactId>
<version>20161106</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.fitnesse.plugins</groupId>
<artifactId>maven-classpath-plugin</artifactId>
<version>1.9</version>
<scope>runtime</scope>
</dependency>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>start-fitnesse</id>
<phase>test</phase>
<configuration>
<tasks>
<echo taskname="fitnesse" message="Starting FitNesse..." />
<java classname="fitnesseMain.FitNesseMain" classpathref="maven.runtime.classpath" fork="true">
<arg line="-p 8000" />
<arg line="-d ." />
</java>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
无需创建 plugins.properties,我就可以启动 Fitnesse 服务器。但是,我必须引入 maven 依赖项来运行我在 pom.xml 旁边创建了一个 plugins.properties 文件的健身测试。 plugins.properties 有:
SymbolTypes = fitnesse.wikitext.widgets.MavenClasspathSymbolType
现在,当我添加此文件时,在启动服务器时出现以下错误:
main:
[fitnesse] Starting FitNesse...
[java] SEVERE: Error while starting the FitNesse [Unable to instantiate component for type fitnesse.wikitext.widgets.MavenClasspathSymbolType]
[java] fitnesse.components.ComponentInstantiationException: Unable to instantiate component for type fitnesse.wikitext.widgets.MavenClasspathSymb
olType
[java] at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:75)
[java] at fitnesse.plugins.PropertyBasedPluginFeatureFactory$8.register(PropertyBasedPluginFeatureFactory.java:152)
[java] at fitnesse.plugins.PropertyBasedPluginFeatureFactory.forEachClass(PropertyBasedPluginFeatureFactory.java:144)
[java] at fitnesse.plugins.PropertyBasedPluginFeatureFactory.forEachObject(PropertyBasedPluginFeatureFactory.java:150)
[java] at fitnesse.plugins.PropertyBasedPluginFeatureFactory.registerSymbolTypes(PropertyBasedPluginFeatureFactory.java:75)
[java] at fitnesse.plugins.PluginsLoader.loadSymbolTypes(PluginsLoader.java:87)
[java] at fitnesse.ContextConfigurator.makeFitNesseContext(ContextConfigurator.java:151)
[java] at fitnesseMain.FitNesseMain.launchFitNesse(FitNesseMain.java:69)
[java] at fitnesseMain.FitNesseMain.launchFitNesse(FitNesseMain.java:58)
[java] at fitnesseMain.FitNesseMain.main(FitNesseMain.java:38)
[java] Caused by: java.lang.reflect.InvocationTargetException
[java] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[java] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[java] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[java] at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
[java] at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:72)
[java] ... 9 more
[java] Caused by: java.lang.NoSuchMethodError: com.google.common.collect.MapMaker.makeComputingMap(Lcom/google/common/base/Function;)Ljava/util/c
oncurrent/ConcurrentMap;
[java] at com.google.inject.internal.Annotations$AnnotationChecker.<init>(Annotations.java:104)
[java] at com.google.inject.internal.Annotations.<clinit>(Annotations.java:122)
[java] at com.google.inject.Key.ensureRetainedAtRuntime(Key.java:362)
[java] at com.google.inject.Key.strategyFor(Key.java:354)
[java] at com.google.inject.Key.get(Key.java:222)
[java] at org.sonatype.guice.bean.binders.ParameterKeys.<clinit>(ParameterKeys.java:23)
[java] at org.codehaus.plexus.DefaultPlexusContainer$ContainerModule.configure(DefaultPlexusContainer.java:801)
[java] at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
[java] at com.google.inject.spi.Elements.getElements(Elements.java:103)
[java] at com.google.inject.spi.Elements.getElements(Elements.java:80)
[java] at org.sonatype.guice.bean.binders.MergedModule.configure(MergedModule.java:54)
[java] at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
[java] at com.google.inject.spi.Elements.getElements(Elements.java:103)
[java] at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
[java] at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
[java] at com.google.inject.Guice.createInjector(Guice.java:94)
[java] at com.google.inject.Guice.createInjector(Guice.java:71)
[java] at com.google.inject.Guice.createInjector(Guice.java:61)
[java] at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:470)
[java] at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:196)
[java] at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:160)
[java] at fitnesse.wikitext.widgets.MavenClasspathExtractor.buildPlexusContainer(MavenClasspathExtractor.java:219)
[java] at fitnesse.wikitext.widgets.MavenClasspathExtractor.buildPlexusContainer(MavenClasspathExtractor.java:215)
[java] at fitnesse.wikitext.widgets.MavenClasspathExtractor.<init>(MavenClasspathExtractor.java:51)
[java] at fitnesse.wikitext.widgets.MavenClasspathSymbolType.<init>(MavenClasspathSymbolType.java:39)
[java] ... 14 more
[java] Java Result: 1
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.552 s
[INFO] Finished at: 2018-03-27T12:58:00-04:00
[INFO] Final Memory: 29M/500M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "fitnesse" could not be activated because it does not exist.
我该怎么做才能让 Fitnesse 工作?
【问题讨论】:
【参考方案1】:您的运行时类路径中可能有另一个库,它使用的 guice 版本比 maven 类路径插件使用的新版本。当我在运行测试时将 selenium 放在类路径上时,我遇到了类似的情况:这破坏了 maven 类路径插件。
我现在使用两种策略来运行健身测试:
-
在本地运行 wiki 时,我使用 maven 类路径插件,但我使用 'standalone.jar' (
java -jar fitness-standalone.zip -p 8000
) 启动 wiki,并将插件的 jar 与依赖项(maven 分类器 'jar-with-dependencies' ) 在“插件”子目录中。这样,我的夹具的所有依赖项都不在 wiki 的类路径上(wiki 启动了一个新的 JVM,其具有由 maven 插件生成的类路径,以运行未使用 maven 类路径插件的夹具)。所以与依赖关系没有冲突。
当我调试装置时,我会在同一个 JVM 中启动 FitNesse 和测试,并使用我的 IDE 生成的类路径。在这种情况下,我不需要 maven 类路径插件(因为类路径已经由 IDE 基于 pom.xml 生成)。然后,我通过将系统属性fitnesse.wikitext.widgets.MavenClasspathSymbolType.Disable
设置为true
来确保停用 maven 类路径插件。然后wiki确实理解了wiki中的!pom
符号,但是插件本身并没有尝试找出所有的maven依赖,防止你遇到的异常。
详细信息可以在我的FitNesse fixtures/project baseline 的pom.xml 中找到。还有一个sample using that baseline to take care of all this is available as a separate project。
【讨论】:
谢谢,这很有帮助。我将 Fitnesse 依赖项移到依赖项列表的顶部,这对我有用。但我肯定会使用上述策略。 我在设置 Fitnesse 时遇到了另一个问题。你能看看这里吗:***.com/questions/49556752/… 这似乎是完全相同的问题:maven-classpath-plugin 和您的固定装置之间的依赖冲突。使用我在这里提到的策略来防止这些。我相信这是同样的问题,但只是 guave 而不是 guice。 谢谢 Fried...我没有时间这样做...但我想现在我必须接受您的建议。以上是关于Fitnesse Maven 类路径错误的主要内容,如果未能解决你的问题,请参考以下文章
Fitnesse maven-classpath-plugin 与 Guava jar 冲突
Fitnesse java.lang.NoClassDefFoundError: javax/faces/validator/ValidatorException