java编译不报错但运行啥都没,SpingMVC项目导入jar包运行报错,编译不报错的解决方式...

在springmvc的web项目中,使用到了导出pdf的iText的jar包,一开始整个工程是使用meaven来管理jar包,但发现在pom.xm配置使用iText,myeclipse就一直卡在54%,无奈尝试这以前直接在src的目录下新建一个lib包,然后复制jar包到里面,选择右键添加到工程里面,这时候,的确工程没有报错,但是一运行,使用到导出pdf的类时,总会报如下的错误:

java.lang.NoClassDefFoundError: com/itextpdf/text/DocumentException

然后就觉得是否是因为meaven下载一半导致的混乱问题,就重启删除iText的部分,发现还是如此,搜了下谷歌,找到这个问题:http://stackoverflow.com/questions/14138623/java-lang-noclassdeffounderror-com-itextpdf-text-documentexception,上面说有如下两种可能导致明明有jar包,但运行报错:

1.你的工程中存在重复的jar,删除掉其中一个,可以在classpath文件里面查看一下是否有不同版本。如下图片:

1287850609990479872.htm

2.如果你是web项目,利用在src新建一个lib文件夹添加到工程里面的,这样是无法识别的,需要放到你的WEB-INF里面,然后点击添加到主目录,这样才不会报错。如下图片:

1287850609990479872.htm

网站的原文如下:

6 down vote

You need to put in the classpath of your web application and not your systems classpath.

And the easiest way to put the jar files on the classpath so that your server can get it at run time is :

PUT THE itextpdf-5.3.4.jar inside the

YOUR_WEBAPP_ROOT --> WEB-INF --> lib folder

so now your jar file should appear here

YOUR_WEBAPP_ROOT --> WEB-INF --> lib --> itextpdf-5.3.4.jar

6 down vote

You need to put in the classpath of your web application and not your systems classpath.

And the easiest way to put the jar files on the classpath so that your server can get it at run time is :

PUT THE itextpdf-5.3.4.jar inside the

YOUR_WEBAPP_ROOT --> WEB-INF --> lib folder

so now your jar file should appear here

YOUR_WEBAPP_ROOT --> WEB-INF --> lib --> itextpdf-5.3.4.jar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值