英文:
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.
<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>
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
属性。
这是在文档中显示的示例:
<javac destdir="${build}"
classpath="xyz.jar"
debug="on">
<src path="${src}"/>
<src path="${src2}"/>
<include name="mypackage/p1/**"/>
<include name="mypackage/p2/**"/>
<exclude name="mypackage/p1/testpackage/**"/>
</javac>
英文:
If you have source files in multiple root directories and want to compile them all into a single root directory, use the <src>
element instead of the srcdir
attribute.
Here is the example shown in the documentation:
<javac destdir="${build}"
classpath="xyz.jar"
debug="on">
<src path="${src}"/>
<src path="${src2}"/>
<include name="mypackage/p1/**"/>
<include name="mypackage/p2/**"/>
<exclude name="mypackage/p1/testpackage/**"/>
</javac>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论