File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Problem with exclude in javac task Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Problem with exclude in javac task" Watch "Problem with exclude in javac task" New topic
Author

Problem with exclude in javac task

Harry Cheng
Greenhorn

Joined: Nov 17, 2002
Posts: 7
Hi all,
I'm new to Ant and I can't get exclude to work in javac. I think I'm doing something wrong, but can't figure out what. I'm hoping someone can point me to the right direction.
This is what my directory structure looks like:
.
build.xml
+src
+my
+stuff
|
|-+server
| *.java
|
|-+printer
| *.java
|
|-+ver-1
| *.java
| *
|
|-+ver-2
| *.java
| *
|
|-+ver-3
*.java
*
I want to compile everything except the stufff in ver-* directories, so I put this in my build.xml file:
<target name="compile">
<javac srcdir="${src}" destdir="${build}" excludes="${src}/**/ver*/"/>
</target>
but it doesn't work, all the java files in all three ver-* directories are still included.
Then I try this,
<target name="compile">
<javac srcdir="${src}" destdir="${build}">
<exclude name="${src}/**/ver*/*.java"/>
</javac>
</target>
I still get the same result. Could anyone tell me what I did wrong?
Thank you very much.
Rufus BugleWeed
Ranch Hand

Joined: Feb 22, 2002
Posts: 1551
1. I'm having trouble understanding your directory structure.
2. javac knows a lot about dependency rules. Could it be that the javac wants those other files so it compiles them without your explicit command?
Harry Cheng
Greenhorn

Joined: Nov 17, 2002
Posts: 7
Sorry! The directory structure didn't come out the way I wanted. Here is what I mean:
./build.xml
./src/my/stuff/server/*.java
./src/my/stuff/printer/*.java
./src/my/stuff/printer/ver-1/*.java
./src/my/stuff/printer/ver-2/*.java
./src/my/stuff/printer/ver-3/*.java
I want to compile everything except the java files in ver-1, ver-2, and ver-3 directories, but both "exclude" and "excludes" didn't work for me as described in the original post. Could anyone tell me what I did wrong?
Thank you very much.
Rufus BugleWeed
Ranch Hand

Joined: Feb 22, 2002
Posts: 1551
Did you see this note in the javac task?
Note: If you wish to compile only source files located in certain packages below a common root, use the include/exclude attributes or <include>/<exclude> nested elements to filter for these packages. Do not include part of your package structure in the srcdir attribute (or nested <src> elements), or Ant will recompile your source files every time you run your compile target. See the Ant FAQ for additional information.

I'm not 100% certain but it looks like it applies.
HTH
Harry Cheng
Greenhorn

Joined: Nov 17, 2002
Posts: 7
I tried this again, if I said
excludes="**/ver*/*"
then it worked, but if I said
excludes="${src}/**/ver*/*"
then it didn't work. Does anyone know why?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with exclude in javac task
 
Similar Threads
Unchanged files get compiled. Why?
Include files in target
How to avoid redundant compiles
Ant xml script & javac + JAVA_HOME classpath
question about exclude task