Java 在Eclipse中使用Ant将运行时生成的文件夹添加为源文件夹

Java 在Eclipse中使用Ant将运行时生成的文件夹添加为源文件夹,java,eclipse,ant,classpath,Java,Eclipse,Ant,Classpath,我正在使用以下一系列软件: 蚂蚁1.7.1 日食太阳神 Java 1.6 Apache thrift 0.8.0 我使用Thrift在Ant中使用以下代码块生成java源代码: <exec executable="thrift-0.8.0.exe" osfamily="windows"> <arg value="-out" /> <arg value="java/src" /> <arg value="--gen" />

我正在使用以下一系列软件:

  • 蚂蚁1.7.1
  • 日食太阳神
  • Java 1.6
  • Apache thrift 0.8.0
  • 我使用Thrift在Ant中使用以下代码块生成java源代码:

    <exec executable="thrift-0.8.0.exe" osfamily="windows">
        <arg value="-out" />
        <arg value="java/src" />
        <arg value="--gen" />
        <arg value="java" />
        <arg file="Sample.thrift" />
    </exec>
    
    在Eclipse中已有的Ant库中是否有这样做的方法


    非常感谢

    eclipse.classpath文件是一个XML文档,因此在其中添加源文件夹需要编辑XML。不幸的是,Ant没有任何用于以任何有意义的方式操作XML的内置工具。我自己也用过编辑.classpath和.project文件,但这是一个你说不想要的外部库


    然而,一切都没有失去,包括。我希望我能说我有足够的经验来给Groovy更多的链接,但是你对某些代码的调用是很可行的,有些调用<代码> AppNoDeNe()/<代码>

    如果你真的不想依赖任何外部的东西,那么你可以考虑使用XSLT样式表来编辑<代码> .CassSPATS< /Cuff>文件(XML)。 添加目录xsl

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:param name="pathToAdd" />
    
      <xsl:strip-space elements="*" />
      <xsl:output method="xml" indent="yes" />
    
      <xsl:template match="@* | node()">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="classpath">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()" />
          <!-- don't add a 2nd copy of the classpathentry if one already exists -->
          <xsl:if test="not(classpathentry[@kind = 'src'][@path = $pathToAdd])">
            <classpathentry kind="src" path="{$pathToAdd}" />
          </xsl:if>
        </xsl:copy>
      </xsl:template>
    </xsl:stylesheet>
    
    <xslt in=".classpath" out=".classpath.edited" style="add-dir.xsl">
      <param name="pathToAdd" expression="java/src" />
    </xslt>
    <move file=".classpath.edited" tofile=".classpath" overwrite="yes" />
    
    
    
    build.xml

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:param name="pathToAdd" />
    
      <xsl:strip-space elements="*" />
      <xsl:output method="xml" indent="yes" />
    
      <xsl:template match="@* | node()">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="classpath">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()" />
          <!-- don't add a 2nd copy of the classpathentry if one already exists -->
          <xsl:if test="not(classpathentry[@kind = 'src'][@path = $pathToAdd])">
            <classpathentry kind="src" path="{$pathToAdd}" />
          </xsl:if>
        </xsl:copy>
      </xsl:template>
    </xsl:stylesheet>
    
    <xslt in=".classpath" out=".classpath.edited" style="add-dir.xsl">
      <param name="pathToAdd" expression="java/src" />
    </xslt>
    <move file=".classpath.edited" tofile=".classpath" overwrite="yes" />
    

    这是一个非常创新的解决方案,我想不出来!!