Unable to execute JasperReports: ClassNotFoundException [duplicate] - java

This question already has an answer here:
NoClassDefFoundError: com/itextpdf/text/DocumentException when exporting jasper to pdf
(1 answer)
Closed 5 years ago.
Trying to execute JasperReports 6.3.1 simple report from Eclipse:
package test.jaspertest;
import java.util.HashMap;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
public class JasperTest {
public static void main(String[] args) {
System.out.println("Start");
try {
JasperReport jasperReport = JasperCompileManager.compileReport("reports/simple.xml");
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport,
new HashMap(),
new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint, "reports/simple.pdf");
} catch (JRException e) {
e.printStackTrace();
}
}
}
Have this out message:
Apr 11, 2017 1:59:41 PM net.sf.jasperreports.extensions.DefaultExtensionsRegistry loadRegistries
WARNING: Extension resource jar:file:/C:/Portable%20Programs/eclipse/packages/jasperreports/dist/jasperreports-javaflow-6.3.1.jar!/jasperreports_extension.properties was found to be a duplicate of jar:file:/C:/Portable%20Programs/eclipse/packages/jasperreports/dist/jasperreports-6.3.1.jar!/jasperreports_extension.properties in classloader sun.misc.Launcher$AppClassLoader#1d16e93
Start
Exception in thread "main" java.lang.NoClassDefFoundError: com/lowagie/text/DocumentException
at net.sf.jasperreports.engine.JasperExportManager.exportToPdfFile(JasperExportManager.java:150)
at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:503)
at test.jaspertest.JasperTest.main(JasperTest.java:24)
Caused by: java.lang.ClassNotFoundException: com.lowagie.text.DocumentException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
Java version 1.8.0.121. I'm not very familiar with Java so please can anyone help me with this issue? Thanks in advance!

You miss the itext-2.1.7.jar in your classpath. add it and the error will go away.
The itext.jar is a dependecy which is needed by jarperReport

Related

getting Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function

ok i am using
eclipse neon
Client-combined-3.1.0-nodeps.jar
for firefox-setup 39.0
and this is my code
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class T1 {
public static void main(String[] args){
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.navigate().to("https://www.orbitz.com/");
driver.manage().window().maximize();
driver.findElement(By.xpath(".//*[#id='primary-header-hotel']")).click();
String result = driver.getPageSource();
System.out.println("result is "+" "+ result);
driver.close();
}
}
and this is the error
Exception in thread "main" java.lang.NoClassDefFoundError:
com/google/common/base/Function at T1.main(T1.java:12) Caused by:
java.lang.ClassNotFoundException: com.google.common.base.Function at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more
i have seen a solution to add path for guava-21.0
but more error
Exception in thread "main" java.lang.IllegalStateException: The path
to the driver executable must be set by the webdriver.gecko.driver
system property; for more information, see
https://github.com/mozilla/geckodriver. The latest version can be
downloaded from https://github.com/mozilla/geckodriver/releases at
com.google.common.base.Preconditions.checkState(Preconditions.java:738)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:111)
at
org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38)
at
org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:112)
at
org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:302)
at
org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:312)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:272)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:267)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:263)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:122)
at T1.main(T1.java:12)
after adding line of code and still Client-combined-3.1.0-nodeps.jar
firefox 52.0.1 and using geckodriver-v0.15.0-win64
and still getting the same error
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class T1 {
public static void main(String[] args){
System.setProperty("webdriver.gecko.driver","C:\\Users\\ahmed\\Desktop\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.navigate().to("https://www.orbitz.com/");
driver.manage().window().maximize();
driver.findElement(By.xpath(".//*[#id='primary-header-hotel']")).click();
String result = driver.getPageSource();
System.out.println("result is "+" "+ result);
driver.close();
}
}
here is the error
Exception in thread "main" java.lang.NoClassDefFoundError:
com/google/common/base/Function at T1.main(T1.java:14) Caused by:
java.lang.ClassNotFoundException: com.google.common.base.Function at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more
In Selenium 3.1.0 you have to do the following to initialize the gecko driver:
System.setproperty("webdriver.gecko.driver","C:\\geckodriver_location\\geckodriver.exe");
Webdriver driver = new Firefoxdriver();
Run your code. It should be success. Let me know if this works for you.

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

package photo;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.github.sarxos.webcam.Webcam;
public class capture {
public static void main(String arg[]) throws IOException {
Webcam webcam = Webcam.getDefault();
webcam.open();
BufferedImage image = webcam.getImage();
ImageIO.write(image, "JPG", new File("test.jpg"));
}
}
I have written this java code to capture photo through webcam, but this code is throwing an error/exception please tell how can I fix it.?
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.github.sarxos.webcam.Webcam.<clinit>(Webcam.java:97)
at photo.capture.main(capture.java:12)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Download SLF4J and put the slf4j-api-1.7.2.jar file onto your class path.

Getting ClassNotFoundException while using Class.forName("com.actitime5.Testcases."+vriable);

I've been messing around with ClassLoaders in java recently, trying to run my automation script code which uses dynamic loading of classes and geting ClassNotFoundException.
##MyCode
package com.actitime5.frameworkengine;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import com.gmail5.Testcases.LoginLogout;
import org.junit.runner.JUnitCore;
public class Init {
public static void main(String args[]) throws Exception
{
Init in=new Init();
String url=in.getConfigValue("url");
ExcelLibrary lib=new ExcelLibrary();
JUnitCore core = new JUnitCore();
int numberofTestcases=lib.getRowCont("Scenario");
System.out.println(numberofTestcases);
for(int i=1;i<=numberofTestcases;i++)
{String status=lib.getExcelData("Scenario", i, 1);
if(status.equals("yes"))
{String scriptnam=lib.getExcelData("Scenario", i, 0);
System.out.println("Sheet Name"+" "+scriptnam);
Class scriptToRun= Class.forName("com.gmail5.Testcases."+scriptnam);
core.run(scriptToRun);
}
}}
##Errors that i am getting :
1
Sheet Name LoginLogout
Exception in thread "main" java.lang.ClassNotFoundException:com.gmail5.Testcases.LoginLogout
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.gmail5.frameworkengine.Init.main(Init.java:24)
The class which I am trying to load is available in package: com.gmail5.Testcases.*;,but still it throws exception
I think your class name has trailing whitespace. Try trim()ming it off before attempting to load the class.
You can confirm this by replacing
System.out.println("Sheet Name"+" "+scriptnam);
with
System.out.println("Sheet Name"+" '"+scriptnam+"'");
I expect this will print out something like the following:
Sheet Name 'LoginLogout '
When I clicked 'edit' to edit your question, I could see there was trailing whitespace after the class name in the stack trace and in your Sheet Name message. (I didn't change anything in your question: I just used the Edit function to see the raw text of your question, and then clicked Cancel.)

Error Invoking Maven

I am trying to invoke maven from a Java class.
My code:
import java.io.File;
import java.util.Arrays;
import javax.xml.ws.spi.Invoker;
import org.apache.maven.shared.invoker.DefaultInvocationRequest;
import org.apache.maven.shared.invoker.DefaultInvoker;
import org.apache.maven.shared.invoker.InvocationRequest;
import org.apache.maven.shared.invoker.MavenInvocationException;
public class MavenProjectBuilder implements ProjectBuilder{
public void BuildProject(String buildPath, String bugID) {
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File(buildPath));
request.setGoals(Arrays.asList( "clean", "install" ));
DefaultInvoker invoker = new DefaultInvoker();
try {
invoker.execute(request);
} catch (MavenInvocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Which returns the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/util/cli/StreamConsumer
at autoEvoSuite.MavenProjectBuilder.BuildProject(MavenProjectBuilder.java:21)
at autoEvoSuite.Main.<init>(Main.java:110)
at tests.GeneralTest.main(GeneralTest.java:18)
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.util.cli.StreamConsumer
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
I did some research and found out it could be a missing dependency, but shouldn't Maven automatically download all missing ones?
Please check if the below dependency is present in your POM.xml, until the dependency is defined in you pom file that jar will not be downloaded to your local repository.
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.17</version>
</dependency>

Getting NoClassDef Error for classes imported through Maven

I have a Maven project in Eclipse created through m2e. It obtains client libraries from a project on GitHub called alternator. The classes seem to be imported fine, in my project, but on running them, it shows a NoClassDefFound error. Here's the code and the error:
Code:
public class Main{
private AlternatorDBClient client;
private DynamoDBMapper mapper;
private AlternatorDB db;
public static void main(String args[]) throws Exception{
new Main().run();
}
public void run() throws Exception {
this.client = new AlternatorDBClient();
this.mapper = new DynamoDBMapper(this.client);
this.db = new AlternatorDB().start();
}
}
Error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/michelboudreau/alternator/AlternatorDBClient
at Main.run(Main.java:17)
at Main.main(Main.java:13)
Caused by: java.lang.ClassNotFoundException: com.michelboudreau.alternator.AlternatorDBClient
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
The AlternatorDBClient class is importing one or more classes which are not on your class path:
import com.amazonaws.*;
import com.amazonaws.handlers.HandlerChainFactory;
import com.amazonaws.http.ExecutionContext;
import com.amazonaws.http.HttpResponseHandler;
import com.amazonaws.http.JsonErrorResponseHandler;
import com.amazonaws.http.JsonResponseHandler;
import com.amazonaws.services.dynamodb.AmazonDynamoDB;
import com.amazonaws.services.dynamodb.model.*;
import com.amazonaws.services.dynamodb.model.transform.*;
import com.amazonaws.transform.JsonErrorUnmarshaller;
import com.amazonaws.transform.JsonUnmarshallerContext;
import com.amazonaws.transform.Unmarshaller;
import com.amazonaws.util.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
You are somehow missing:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
</dependency>
as a dependency in your project pom. As AlexR stated, please post your pom.

Categories