使用第三方.jar文件时java.lang.NoClassDefFoundError [英] java.lang.NoClassDefFoundError when using a third party .jar file

查看:560
本文介绍了使用第三方.jar文件时java.lang.NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NetBeans.我有一个简单的项目,它以精美的格式打印一些作为参数发送的数据. 这是引发异常的代码:

I'm using NetBeans. I have a simple project, which prints in a fancy format some data sent as arguments. This is the code that throws an Exception:

        JasperDesign design =  JRXmlLoader.load("Certificate.jrxml");
        JasperReport report = JasperCompileManager.compileReport(design);
        JasperPrint print = JasperFillManager.fillReport(report, new HashMap(), new ClientList(args).getClients());
        JPanel panel= new JRViewer(print);

每当创建Jasper类时,就会抛出这些异常. 我还尝试了System.getProperty("java.class.path"),它包括"jasperreports-5.0.1.jar"文件. 我究竟做错了什么?我知道,只要有一个类在编译时可用,但在运行时不可用,就会抛出这些异常.但是jar在那里!

These Exceptions are thrown whenever a Jasper class is created. I also tried System.getProperty("java.class.path") and it includes the "jasperreports-5.0.1.jar" file.. What am I doing wrong? I know these Exceptions are thrown whenever a class is available at compile time, but not at runtime.. But the jar is there!

请求的堆栈跟踪:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester

at certificado.Certificado.main(Certificado.java:31)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Digester

at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

at java.lang.ClassLoader.loadClass(ClassLoader.java:423)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

at java.lang.ClassLoader.loadClass(ClassLoader.java:356)

... 1 more

Java Result: 1

推荐答案

您可能正在针对Jasper jar进行编译,但是在运行时该jar有其自己的依赖项,您也应该包括这些依赖项.

You may be compiling against the Jasper jar ok, but at runtime that jar has its own dependencies, and you should include those too.

根据您的堆栈跟踪记录,您需要 Apache Commons Digester .我也许会使用Maven进行构建,然后让Maven(希望)为您解决依赖关系集.您可以使用 Jar搜索引擎来找到这些依赖项,但是它们不能确定为您匹配这些罐子的版本.

According to your stacktrace you need Apache Commons Digester. I would perhaps build using Maven, and let Maven (hopefully) resolve the set of dependencies for you. You can use a Jar search engine to find these dependencies, but they won't determine matching versions of those jars for you.

这篇关于使用第三方.jar文件时java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆