不知道您是否正在执行与我正在执行的操作类似的操作,但是Im在使用Maven的单独组件中使用JAXB从XSD生成了源Java负载。可以说该工件称为“基本模型”
我想导入包含Java源代码的工件,并在“基本模型”工件jar中的所有类上运行休眠模式,而不是明确指定每个对象。我添加了“基本模型”作为我的休眠组件的依赖项,但麻烦的是persistence.xml中的标记仅允许您指定绝对路径。
我的解决方法是将我的“基本模型” jar依赖项明确复制到我的目标目录,然后剥离其版本。因此,如果我构建“基本模型”工件,则会生成“基本模型1.0-SNAPSHOT.jar”,而“复制资源”步骤会将其复制为“基本模型.jar”。
因此,在您的休眠组件的pom中:
<!-- We want to copy across all our artifacts containing java code
generated from our scheams. We copy them across and strip the version
so that our persistence.xml can reference them directly in the tag
<jar-file>target/dependency/${artifactId}.jar</jar-file> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<includeArtifactIds>base-model</includeArtifactIds>
<stripVersion>true</stripVersion>
</configuration>
</plugin>
然后在下一阶段将“休眠类”称为“进程类”:
<!-- Generate the schema DDL -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>generate-ddl</id>
<phase>process-classes</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
</execution>
</executions>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>annotationconfiguration</implementation>
<outputDirectory>/src/main/java</outputDirectory>
</component>
</components>
<componentProperties>
<persistenceunit>mysql</persistenceunit>
<implementation>jpaconfiguration</implementation>
<create>true</create>
<export>false</export>
<drop>true</drop>
<outputfilename>mysql-schema.sql</outputfilename>
</componentProperties>
</configuration>
</plugin>
最后,在我的persistence.xml中,可以这样显式设置jar的位置:
<jar-file>target/dependency/base-model.jar</jar-file>
并添加属性:
<property name="hibernate.archive.autodetection" value="class, hbm"/>