简体   繁体   English

Servlet引用了Maven项目-NoClassDefFoundError

[英]Servlet referencing a Maven project - NoClassDefFoundError

I have a Maven project that uses Hibernate and PostgreSQL, and it's working fine on it's own. 我有一个使用Hibernate和PostgreSQL的Maven项目,它本身可以很好地工作。 Now I want to use some classes from this project (essentially the database) in a servlet, but now things break. 现在,我想在Servlet中使用此项目中的某些类(本质上是数据库),但是现在情况不妙了。

I get a java.lang.NoClassDefFoundError: javax/persistence/Persistence error when accessing the servlet in Tomcat. 在Tomcat中访问servlet时,出现java.lang.NoClassDefFoundError: javax/persistence/Persistence错误。

I'm thinking that somehow the Maven dependencies don't get "forwarded" to the servlet project, but I don't know what to do about it. 我在想,Maven依赖关系不会“转发”到servlet项目,但是我不知道该怎么办。 I've added the Maven project to the servlet build path, and also to its "Web Deployment Assembly"... what more do I need to do? 我已经将Maven项目添加到servlet的构建路径中,并且还添加到了它的“ Web部署程序集”中……我还需要做什么?

Please try this dependency. 请尝试这种依赖性。

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final-redhat-3</version>
</dependency>

1.Check for all the jars, make sure that all the dependencies are added. 1.检查所有罐子,确保添加了所有依赖项。

2.Clean your tomcat 2.清理你的tomcat

Try adding Runtime dependencies. 尝试添加运行时依赖项。

3.Right click on your project and select Properties-> Deployment Assembly 3.右键单击您的项目,然后选择属性->部署程序集

  • click on Add 点击添加
  • select Java Build Path Entries 选择Java构建路径条目
  • select Maven Dependencies 选择Maven依赖关系
  • Finish

Re-run your server. 重新运行您的服务器。

Hope this helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM