【发布时间】:2015-06-03 21:04:12
【问题描述】:
我正在尝试在我的 project-web-server 中初始化 Hibernate 会话。为此,我正在使用我编写的 project-data-model 库,该库在 maven 中作为依赖项链接:
项目网络服务器 pom.xml:
<dependency>
<groupId>com.preoject.server</groupId>
<artifactId>project-data-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
HibernateSession.java 因此在 project-data-model 中;这就是我在 project-web-server 中使用它的方式:
public class ServerConfig implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
try {
HibernateSession.initialize();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public void contextDestroyed(ServletContextEvent event) {
// Do stuff on shutdown.
}
}
尽管我将数据模型项目引用为依赖项,但我得到了 java.lang.NoClassDefFoundError 异常:
java.lang.NoClassDefFoundError: org/hibernate/Interceptor
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:65)
at com.project.datamodel.HibernateSession.initialize(HibernateSession.java:19)
at com.project.web.server.ServerConfig.contextInitialized(ServerConfig.java:14)
...
我不知道我必须在这里做什么。 war/WEB-INF/lib 文件夹不包含任何 Hibernate 相关库;这可能是问题吗?我不确定,因为我已将 Hibernate 依赖项添加到父 pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.1.Final</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.0.1.Final</version>
</dependency>
【问题讨论】:
-
您如何实际构建和部署应用程序?
-
@DraganBozanovic 我不太确定我是否理解你的问题。什么意思?
-
您必须构建您的应用程序才能运行它。如果您不知道它是如何构建的,我假设您只是尝试在依赖 maven Eclipse 插件将所有部分连接在一起的 IDE (Eclipse) 中运行它?
-
@DraganBozanovic 基本上是的,但我意识到 Maven 不会将库复制到 GWT 应用程序所需的
/lib目录中。现在我正在寻找一种方法来告诉 Maven 将依赖项移动到war/WEB-INF/lib。 -
@DraganBozanovic 我当然设法手动复制了这些文件 - 然后它就可以工作了。但这当然不是我使用 Maven 项目的原因^^