При установке моего проекта в локальный репозиторий с помощью команды mvn install
файлы отображения hibernate исключаются из сгенерированного JAR .
.* файлы в src / main / resources / traffic_domain / mapping / , поэтому все должно быть в порядке, как это следует стандартному расположению каталогов для maven.
мой POM-файл выглядит так:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>masters.traffic</groupId>
<artifactId>traffic_domain</artifactId>
<packaging>jar</packaging>
<name>traffic_domain</name>
<version>0.1.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Структура каталогов следующая:
traffic_domain
|-- pom.xml
|-- src
|-- main
|-- java
|-- ...
|-- resources
|-- traffic_domain
|-- mapping
|-- Access.hbm.xml
|-- *.hbm.xml
traffic_domain.jar - это один из JAR-файлов, необходимых для запуска моего веб-приложения .При запуске tomcat я получаю такое исключение:
Причина: org.hibernate.MappingNotFoundException: resource: main / resources / traffic_domain / mapping / Access.hbm.xmlне найден в ...
Как это исправить?
Обновление: ОК (объявление. Pascal Thivent комментарий), то есть содержимое сгенерированного JAR после вызова mvn clean package
:
c:\Users\jwa\Desktop\tets\traffic_domain\target>jar xvf traffic_domain-0.1.0.jar
created: META-INF/
inflated: META-INF/MANIFEST.MF
created: main/
created: main/java/
created: main/java/traffic_domain/
created: main/java/traffic_domain/bean/
created: main/java/traffic_domain/logic/
created: main/java/traffic_domain/tools/
inflated: Access.hbm.xml
inflated: District.hbm.xml
inflated: main/java/traffic_domain/bean/Access.class
inflated: main/java/traffic_domain/bean/District.class
inflated: main/java/traffic_domain/bean/PostalCode.class
inflated: main/java/traffic_domain/bean/Street.class
inflated: main/java/traffic_domain/bean/TrafficCondition.class
inflated: main/java/traffic_domain/logic/AccessFacade.class
inflated: main/java/traffic_domain/logic/LocationFacade.class
inflated: main/java/traffic_domain/logic/TrafficConditionFacade.class
inflated: main/java/traffic_domain/tools/HibernateUtil.class
inflated: PostalCode.hbm.xml
inflated: Street.hbm.xml
inflated: TrafficCondition.hbm.xml
created: META-INF/maven/
created: META-INF/maven/masters.traffic/
created: META-INF/maven/masters.traffic/traffic_domain/
inflated: META-INF/maven/masters.traffic/traffic_domain/pom.xml
inflated: META-INF/maven/masters.traffic/traffic_domain/pom.properties
Для сравнения, вот содержимое этого JAR, созданного Eclipce, который является working :
C:\Users\jwa\Desktop\correct>jar xvf traffic_domain.jar
inflated: main/java/traffic_domain/bean/PostalCode.class
inflated: traffic_domain/mapping/Access.hbm.xml
created: main/resources/
created: main/resources/traffic_domain/
inflated: traffic_domain/mapping/Street.hbm.xml
inflated: main/java/traffic_domain/logic/AccessFacade.class
inflated: main/resources/traffic_domain/mapping/TrafficCondition.hbm.xml
inflated: traffic_domain/mapping/PostalCode.hbm.xml
created: main/java/traffic_domain/bean/
inflated: main/java/traffic_domain/tools/HibernateUtil.class
created: main/
inflated: main/java/traffic_domain/bean/TrafficCondition.class
inflated: mapping/Street.hbm.xml
inflated: PostalCode.hbm.xml
inflated: main/java/traffic_domain/bean/Access.class
created: traffic_domain/mapping/
inflated: District.hbm.xml
created: traffic_domain/
inflated: traffic_domain/mapping/TrafficCondition.hbm.xml
created: main/java/traffic_domain/tools/
inflated: Access.hbm.xml
inflated: traffic_domain/mapping/District.hbm.xml
created: main/java/traffic_domain/logic/
created: mapping/
created: main/resources/traffic_domain/mapping/
inflated: mapping/TrafficCondition.hbm.xml
inflated: main/resources/traffic_domain/mapping/Access.hbm.xml
inflated: mapping/Access.hbm.xml
inflated: main/java/traffic_domain/bean/Street.class
created: main/java/
inflated: main/java/traffic_domain/logic/TrafficConditionFacade.class
inflated: main/resources/traffic_domain/mapping/PostalCode.hbm.xml
created: main/java/traffic_domain/
inflated: TrafficCondition.hbm.xml
inflated: main/resources/traffic_domain/mapping/District.hbm.xml
inflated: mapping/PostalCode.hbm.xml
inflated: Street.hbm.xml
inflated: main/resources/traffic_domain/mapping/Street.hbm.xml
inflated: main/java/traffic_domain/logic/LocationFacade.class
inflated: main/java/traffic_domain/bean/District.class
inflated: mapping/District.hbm.xml
Вот часть hibernate.cfg.xml , которая загружает сопоставления (изменено после axtavt advice):
<mapping resource="traffic_domain/mapping/Access.hbm.xml"/>
<mapping resource="traffic_domain/mapping/Street.hbm.xml"/>
<mapping resource="traffic_domain/mapping/District.hbm.xml"/>
<mapping resource="traffic_domain/mapping/PostalCode.hbm.xml"/>
<mapping resource="traffic_domain/mapping/TrafficCondition.hbm.xml"/>