gpt4 book ai didi

ant - 如何使用 Ant(或 Maven)动态创建 jaxb.in​​dex 文件

转载 作者:行者123 更新时间:2023-12-04 15:37:36 25 4
gpt4 key购买 nike

这更多的是知识共享,而不是提出问题。认为这个小 Ant 片段可能对某人有用。

<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>

最佳答案

继 Gary 的示例之后,我采用了它并对其进行了扩展,因此它可以用于多个包目录。如果您的插件依赖项中有 antcontrib 依赖项,则以下应该有效:

<target>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.dependency.classpath" />
<for param="dto-dir">
<path>
<dirset dir="${basedir}/src/main/java">
<include name="com/example/**/dto"/>
</dirset>
</path>
<sequential>
<property name="@{dto-dir}" basedir="${basedir}/src/main/java" relative="true" location="@{dto-dir}" />
<echo message="Creating jaxb.index file for directory: ${@{dto-dir}}" />
<echo message="@{dto-dir}" />
<fileset id="@{dto-dir}_dtos" dir="@{dto-dir}">
<include name="*Dto.java" />
</fileset>
<pathconvert property="@{dto-dir}_contents" refid="@{dto-dir}_dtos" pathsep="${line.separator}">
<chainedmapper>
<flattenmapper />
<globmapper from="*.java" to="*" casesensitive="false" />
</chainedmapper>
</pathconvert>
<echo file="${project.build.outputDirectory}/${@{dto-dir}}/jaxb.index" message="${@{dto-dir}_contents}" />
</sequential>
</for>
</target>

正如您所看到的,我无论如何都不是 Ant 专家,我不得不做一些奇怪的事情来创建唯一的属性名称,但它对我有用。

关于ant - 如何使用 Ant(或 Maven)动态创建 jaxb.in​​dex 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3361321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com