我正在为具有速度的log4j appender编写自定义布局,但我无法让它运行
错误如下:
java.lang.NoClassDefFoundError:org.apache.velocity.runtime.RuntimeInstance中的org / apache / commons / collections / ExtendedProperties . (RuntimeInstance.java:183)org.apache.velocity.app.VelocityEngine . (VelocityEngine.java: 60)at nz.ac.massey.cs.sdc.assign1.s06013597.VelocityLayout . (VelocityLayout.java:16)at nz.ac.massey.cs.sdc.assign1.s06013597.VelocityLayoutTest.test(VelocityLayoutTest.java:36 )java.base / jdk.internal.refut上的java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method),java.base / jdk.internal.reflect中的java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) .delegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在java.base / java.lang.reflect.Method.invoke(Method.java:564)org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java: 50)org.junit.inun.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMeth) od.java:47)org.junit.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)atg.junit.runners .blockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)atg.junit .runners.ParentRunner $ 1.schedule(ParentRunner.java:71)org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)at at org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)org.eclipse.junt.internal.junit4.runner.JUnit4TestReference.run上的org.junit.runners.ParentRunner.run(ParentRunner.java:363) (JUnit4TestReference.java:86)org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java) :538)在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)位于org.eclipse的org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) . jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)引起:java.lang.ClassNotFoundException:org.apache.commons.collections.ExtendedProperties at java.base / jdk.internal.loader.BuiltinClassLoader.loadClass (BuiltinClassLoader.java:582)java.base / jdk.internal.loader.ClassLoaders $ AppClassLoader.loadClass(ClassLoaders.java:190)at java.base / java.lang.ClassLoader.loadClass(ClassLoader.java:499) . ..还有27个
这是我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>assign251_2</groupId>
<artifactId>s06013597</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>s06013597</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>site</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</reporting>
</project>
1 回答
您的代码运行正常,您的测试在我的机器上传递 . 您应该重新导入maven依赖项,和/或从.m2文件夹中删除apache / commons / collection目录 .