这更多的是知识共享,而不是提问。认为这个小蚂蚁片段可能对某人有用。
<target name="create-jaxb-index" depends="compile">
<!-- Create a suitable jaxb.index file on the fly to remove the need for an ObjectFactory
jaxb.index is a simple list of the domain objects without package or extension, e.g.
org.example.Domain.java -> Domain
-->
<fileset id="domain-sources" dir="${src}">
<include name="org/example/*.java"/>
</fileset>
<pathconvert property="domain-list" refid="domain-sources" pathsep="${line.separator}">
<chainedmapper>
<flattenmapper/>
<globmapper from="*.java" to="*" casesensitive="false"/>
</chainedmapper>
</pathconvert>
<echo file="${target}/classes/org/example/jaxb.index" message="${domain-list}"/>
</target>
好的,好的,所以它并没有完全存储所有包名称,以便它可以重建适当的文件结构,但它足以让你开始。
希望能帮助到你。
此外,您可以像这样将这个小片段(减去目标元素)插入到 Maven 构建中:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<tasks>
<!-- Create a suitable jaxb.index file on the fly to remove the need for an ObjectFactory
jaxb.index is a simple list of the domain objects without package or extension, e.g.
org.example.Domain.java -> Domain
-->
<fileset id="domain-sources" dir="${build.sourceDirectory}">
<include name="org/example/domain/*.java"/>
</fileset>
<pathconvert property="domain-list" refid="domain-sources" pathsep="${line.separator}">
<chainedmapper>
<flattenmapper/>
<globmapper from="*.java" to="*" casesensitive="false"/>
</chainedmapper>
</pathconvert>
<echo file="${build.outputDirectory}/org/example/domain/jaxb.index" message="${domain-list}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>