java中的web应用程序错误的是_我的Java Web应用程序中的ClassNotFoundException ...

What does this mean?

Thrown when an application tries to load in a class through its string name using:

The forName method in class Class.

The findSystemClass method in class ClassLoader.

The loadClass method in class ClassLoader.

but no definition for the class with the specified name could be found.

通常,尝试以此形式手动打开连接时会发生这种情况:

String jdbcDriver = "...'; //name of your driver

Class.forName(jdbcDriver);

或者,当您引用属于外部库的类时,奇怪的是,当应用程序服务器尝试部署应用程序时,无法加载此类.

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

最后一部分说明了一切:类在编译时存在,即我通过IDE编译应用程序时,但它在运行时不可用,即部署应用程序时.

how can I fix it?

在Java Web应用程序中,应用程序使用的所有第三方库都必须位于WEB-INF / lib文件夹中.确保将所有必需的库(罐)放在那里.您可以轻松检查:

-

- WEB-INF

- lib

+ jar1

+ jar2

+ ...

- META-INF

-

这个问题通常出现在JDBC连接jar(MySQL,Derby,MSSQL,Oracle等)或web MVC框架库(如JSF或Spring MVC)中.

考虑到某些第三方库依赖于其他第三方库,因此您必须在WEB-INF / lib中添加所有这些库才能使应用程序正常工作.一个很好的例子是RichFaces 4库,where you have to download and add the external libraries manually.

Maven用户注意事项:除非您将库设置为提供,测试或系统,否则不应遇到这些问题.如果设置为提供,则您负责在类路径中的某处添加库.您可以在此处找到有关依赖范围的更多信息:Introduction to the Dependency Mechanism

如果必须在将在您的应用程序服务器上部署的多个应用程序之间共享库,例如两个应用程序的MySQL连接器,还有另一种选择.不是使用自己的MySQL连接器库部署两个war文件,而是将此库放在服务器应用程序的公共库文件夹中,这将使库能够位于所有已部署应用程序的类路径中.

该文件夹与应用服务器不同.

> Tomcat 7/8:< tomcat_home> / lib

> JBoss 7 / Wildfly:< jboss_home> / standalone / lib

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值