0

当源文件是包的一部分并且源树的目录结构不遵循包层次结构时,javac ant任务无法编译 java 类。但是我看到在不同的机器上,相同的

构建.xml

文件运行良好。

例如,如果我有一个带有包的 java 文件,com.abc.myapp.server.base并且如果我的源文件放在C:\mySource\base文件夹下,javac则无法编译此类。但是,如果我将.java源文件移动到文件C:\mySource\com\abc\myapp\server\base夹下,一切都会好起来的。

我在Windows 7上使用ANT 1.8.0版本和JDK 1.7.0_17版本。

请指教

4

1 回答 1

0

It sounds like you're not setting up your directory structure to match the packages of your java source files. The source for the class "org.example.abc.HelloWorld" should live in a directory like /src/org/example/abc.

Typically, you'd want your build.xml to be at the top-level of whatever project you're trying to build, and then the javac task inside it can reference the source directory where your package structure starts.

Something like this:

<project name="example" default="compile">
    <target name="compile" description="compiles">
        <mkdir dir="build"/>
        <javac srcdir="src" destdir="build"/>
    </target>
</project>

This is obviously very over simplified, but should help get you started.

If you're still having trouble, post your build.xml and some description of your project's layout so we can help.

于 2013-03-19T14:35:53.840 回答