Reputation:
I have the following directory structure:
MyApp/
src/main/java/
com/
myapp/
api/
IFizz
FizzLoader
impl/
core/
FizzImpl
Cat
Dog
Tree
...many other objects
src/test/java
...
build/
lib/
...
I want to only compile everything under src/main/java/com/myapp/api
as well as com.myapp.impl.core.FizzImpl
, such that Cat
, Dog
, Tree
etc. do not get compiled (and are thus excluded).
In by Ant build (build.xml
), I configure the following main.compile.path
:
<path id="src.path">
<fileset dir="src/main/java/com/myapp/api">
<include name="**.*java"/>
</fileset>
</path>
<path id="lib.main.path">
<fileset dir="lib/main">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="main.compile.path">
<path refid="src.path" />
<path refid="lib.main.path" />
<fileset dir="src/main/java" includes="com/myapp/impl/core/**/*" />
</path>
And then the following main-compile
target:
<target name="main-compile">
<javac includeantruntime="false" srcdir="src/main/java/com/myapp/api"
destdir="gen/bin/main" debug="on">
<classpath refid="main.compile.path"/>
</javac>
</target>
When I run main-compile
, I get the following build exception:
[javac] /home/myuser/eclipse/workspace/MyApp/src/main/java/com/myapp/api/FizzLoader.java:14: package com.myapp.impl.core does not exist
[javac] import com.myapp.impl.core.FizzImpl;
[javac] ...(omitting rest of trace but available upon request)
Here, FizzLoader
is creating an instance of FizzImpl
, and so I need this on the compile path.
Why does Ant not see the com.myapp.impl.core.FizzImpl
that I have selectively added to the main.compile.path
? Thanks in advance!
Upvotes: 0
Views: 1348
Reputation: 691715
The classpath of javac should refer to directories and jar files containing the root of compiled class files trees. It should not refer to Java files.
Similarly, the source directory should refer to the root of the package tree of the source files. Not to directories corresponding to packages, inside the package tree.
Your compile task should look like
<target name="main-compile">
<javac includeantruntime="false"
srcdir="src/main/java"
destdir="${gen.bin.main.dir}"
debug="on"
includes="com/myapp/api/**/*.java, com/myapp/impl/core/FizzImpl/**/*.java">
<classpath refid="lib.main.path"/>
</javac>
</target>
Upvotes: 1