问题
Tried to create advanced HTML
reports using extentReports
jar, but it is throwing below error.
java.lang.NoClassDefFoundError: freemarker/template/TemplateModelException
Code:
public class XtentReport {
WebDriver driver;
ExtentReports report;
ExtentTest logger;
@Test public void verifyXReport() {
report = new ExtentReports("D:\\Selenium_Reports\\AdvanceReport.html");
logger=report.startTest("StartingTC"); driver= new FirefoxDriver();
driver.manage().window().maximize(); logger.log(LogStatus.INFO,"Browser is up and running");
driver.get("google.com");
logger.log(LogStatus.PASS,"Test completed"); report.endTest(logger);
report.flush();
}
}
回答1:
Maven: If maven is used as a build tool then just add the below dependency
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
No Maven: If maven is not used, add the below jar to the classpath.
Download freemarker-2.3.23.jar from the below link. http://central.maven.org/maven2/org/freemarker/freemarker/2.3.23/freemarker-2.3.23.jar
If a different version is needed then use the below link and choose the version needed. http://central.maven.org/maven2/org/freemarker/freemarker
回答2:
You need to add the freemarker-<version>.jar
to yor classpath.
回答3:
If someone came here because have this same error using XDocReport, pay attention that it's just a WARN
:).
来源:https://stackoverflow.com/questions/38221933/java-lang-noclassdeffounderror-freemarker-template-templatemodelexception