Ant Javac编译子包中的类文件到父级src目录。

huangapple go评论72阅读模式
英文:

Ant Javac compile subpackage class files to the parent src directory

问题

我希望Ant 1.9能够将Servlet类编译到父源代码目录中,但文件系统中的文件位于包中。不,Servlet文件中没有声明包。

该代码部署在同一个目录中的所有Servlet中。我想我可以创建一个Ant复制命令来完成这个任务,但我更希望有一个Ant javac的解决方案。

手动操作将是'javac -d .. *.java',在切换到每个子目录后执行,不包括已在默认包中的文件。这非常不规范,但我无法更改包的定义方式,也无法更改代码执行的URL。

<target name="compileServlet" description="Compiles Java source files.">
    <javac srcdir="${servlets.dir}" destdir="${servlets.dir}" debug="true" encoding="ISO-8859-1" source="1.7" target="1.7" failonerror="true">
        <classpath path="${env.CLASSPATH}" />
        <include name="**/*.java"/>
    </javac>
</target>

目前,当我运行此Ant build.xml时,没有生成任何类文件。有没有想法如何解决这个问题?

英文:

I would like Ant 1.9 to be able to compile servlet classes to the parent src directory, but the file system has the files in packages. No, the packages are not declared in the servlet files.

The code is deployed with all the servlets in the same directory. I supposed I can create an ant copy command to do this, but I would prefer there be an ant javac solution.

Manually this would be 'javac -d .. *.java' after changing to each subdirectory, not including the files already in the default package. This is highly irregular, but I cannot change the how the packages are defined nor can I change the urls from which the code is executed from.

&lt;target name=&quot;compileServlet&quot; description=&quot;Compiles Java source files.&quot;&gt;
            &lt;javac srcdir=&quot;${servlets.dir}&quot; destdir=&quot;$(servlets.dir}&quot; debug=&quot;true&quot; encoding=&quot;ISO-8859-1&quot; source=&quot;1.7&quot; target=&quot;1.7&quot; failonerror=&quot;true&quot;&gt;
                    &lt;classpath path=&quot;${env.CLASSPATH}&quot; /&gt;
                    &lt;include name=&quot;**/*.java&quot;/&gt;
            &lt;/javac&gt;
    &lt;/target&gt;

Right now when I run this ant build.xml, no class files are generated. Any thoughts how I can solve this issue?

答案1

得分: 0

如果您有多个根目录中的源文件,并希望将它们全部编译到单个根目录中,请使用<src>元素而不是srcdir属性。

这是在文档中显示的示例:

&lt;javac destdir=&quot;${build}&quot;
       classpath=&quot;xyz.jar&quot;
       debug=&quot;on&quot;&gt;
  &lt;src path=&quot;${src}&quot;/&gt;
  &lt;src path=&quot;${src2}&quot;/&gt;
  &lt;include name=&quot;mypackage/p1/**&quot;/&gt;
  &lt;include name=&quot;mypackage/p2/**&quot;/&gt;
  &lt;exclude name=&quot;mypackage/p1/testpackage/**&quot;/&gt;
&lt;/javac&gt;
英文:

If you have source files in multiple root directories and want to compile them all into a single root directory, use the &lt;src&gt; element instead of the srcdir attribute.

Here is the example shown in the documentation:

&lt;javac destdir=&quot;${build}&quot;
       classpath=&quot;xyz.jar&quot;
       debug=&quot;on&quot;&gt;
  &lt;src path=&quot;${src}&quot;/&gt;
  &lt;src path=&quot;${src2}&quot;/&gt;
  &lt;include name=&quot;mypackage/p1/**&quot;/&gt;
  &lt;include name=&quot;mypackage/p2/**&quot;/&gt;
  &lt;exclude name=&quot;mypackage/p1/testpackage/**&quot;/&gt;
&lt;/javac&gt;

huangapple
  • 本文由 发表于 2020年8月13日 08:18:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63386314.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定