Jboss 7.1.1正确的休眠依赖关系 [英] Jboss 7.1.1 correct hibernate dependencies

查看:88
本文介绍了Jboss 7.1.1正确的休眠依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看一个旧项目的pom.xml,该项目正试图在Jboss AS 7.1.1上运行.此pom包含很多依赖项,其中包含以下工件:

I'm reviewing pom.xml of an old project which I'm trying to run on Jboss AS 7.1.1. This pom contains a lot of dependencies with artifacts like:

  • 休眠核心
  • 休眠验证器
  • hibernate-jpa-2.0-api
  • hibernate-entitymanager
  • ...

由于Jboss 7.1.1具有模块org.hibernate,因此我通过创建具有以下内容的\META-INF\jboss-deployment-structure.xml设法除去了hibernate-core以外的所有依赖项:

As Jboss 7.1.1 has a module org.hibernate I've managed to remove these dependencies except of hibernate-core by creating \META-INF\jboss-deployment-structure.xml with following content:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
    <deployment>
        <dependencies>
            <module name="org.hibernate"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

因此,为了能够编译WAR文件,我需要具有此依赖项

So in order to be able to compile WAR file I need to have this dependency

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
</dependency>

,但我不明白为什么不能使用provided范围设置它.如果它包含在org.hibernate模块中,为什么不能这样做?如果将其设置为provided,则会出现以下错误:

but I can't understand why I can't set it with provided scope. If it is included in org.hibernate module, why I can't do so? If I set it as provided, I'm getting the following error:

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

我想将其设置为provided范围,只是将其从WAR文件中排除

I want to set it with provided scope just to exclude it from WAR file

推荐答案

如果您在项目中使用maven更好地提供了休眠和受支持的模块作为清单条目,则可以使用jboss-deployment-structure.xml而不是jboss-deployment-structure.xml.您可以通过遵循pom.xml中的代码来实现此目的

Instead of jboss-deployment-structure.xml if you are using maven in project better to provide hibernate and supported module as manifest entry. you can achieve this by following code in pom.xml

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Dependencies>
org.infinispan,org.hibernate
</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>

然后使用提供的范围添加其他必需的依赖项,以便可以在运行时加载它们而不会在战争中捆绑在一起,请使用以下示例.

then add your other required dependencies with the scope provided so they can be loaded at run time with out bundling in war, use following as an example.

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.0.1.Final</version>
        <scope>provided</scope>
    </dependency> 
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.2.0.Final</version>
        <scope>provided</scope>
    </dependency>
   <dependency>
        <groupId>org.hibernate.common</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>4.0.1.Final</version>
        <classifier>tests</classifier>
        <scope>provided</scope>
    </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-c3p0</artifactId>
        <version>4.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.0.1.Final</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
        <scope>provided</scope>
    </dependency>

这篇关于Jboss 7.1.1正确的休眠依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆