我正在使用jersey构建rest api,它需要与mysql数据库通信。决定使用Hibernate,但是我在第51行获得了这个异常,我初始化了SessionFactory对象。这是:
51 SessionFactory sessionFactory = new Configuration()
52 .configure()
53 .buildSessionFactory();
这是错误:
Apr 28, 2016 1:05:03 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [org.lockedout.pollinator.api.MyApp] in context with path [/resources] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration] with root cause
java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.lockedout.pollinator.api.PollsResource.createNewPoll(PollsResource.java:51)
对可能导致错误的原因有任何见解?
答案 0 :(得分:1)
您可以使用maven war插件来包含运行时所需的jar
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingIncludes>WEB-INF/lib/hibernate-core*.jar,WEB-INF/lib/someOther*.jar</packagingIncludes>
</configuration>
</plugin>
</plugins>
</build>