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-core
- hibernate-validator
- hibernate-jpa-2.0-api
- hibernate-entitymanager
- ...
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>
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>
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
I want to set it with provided
scope just to exclude it from WAR file
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>