Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to compile only specific .java files, not the whole src

 
dani abdallah
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

The src attribute specifies where the source code is but i do not want to compile the whole source, just individual .java files. I can't find the attribute to do this, anyone knows?

regards,

Dani
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the 'includes' or 'excludes' attributes to identify the files to compile (or not to compile). Alternately, the javac task is an implicit FileSet and thus support nested <include> and <exclude> directives.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I assume you're asking a question about Ant, and not something else?)
 
dani abdallah
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:(I assume you're asking a question about Ant, and not something else?)


Yes my question was about ant, thank you for the response. Do you mind giving me a quick example one how I would exclude the file test.java file for example?

Right now to compile the source I would do, for example:

<javac srcdir="${src}" destdir="${build}"/>


how would I use the excludes attribute, does this make sense:

<javac srcdir="${src}" destdir="${build}"
excludes=""${src}/test.java"/>

Regardsm

Dani
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Close! Take a look at the ANT documentation on how to perform exclude and include filesets
 
dani abdallah
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martijn Verburg wrote:Close! Take a look at the ANT documentation on how to perform exclude and include filesets


Thanks I have looked, and what I have come up with is this :

<target name="compile2">
<javac destdir="${root}/build" source="1.5" >
<src path="${src}"/>
<exclude name="${src}/Package/test.java"/>
<classpath refid="lib"/>
</javac>
</target>

but it is still not working (I gather from the fact that still the same number of files are being compiles)

To explain what I am trying to do, I want to create a jar file with only a subset of all the classes, not the whole source, I was thinking that I would compile just part of the source and then create the jar. In retrospect, I am thinking that another possibility would be to compile the source and then only include some of it in the jar.

What would your advice be? Also can you spot anything wrong with the code above?

Thanks a lot

Dani
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have different *packaging* requirements, that would be best handled during the packaging part of things.
 
dani abdallah
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:If you have different *packaging* requirements, that would be best handled during the packaging part of things.


Right, I see, so then I will have to use the exclude attribute while creating the jar file. Can you spot any obvious mistake with how I am using the exclude attribute in the code above?

regards,

Dani
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're almost there! Run ant with the debug flag and you should see it extrapolate your exclude path....
 
dani abdallah
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martijn Verburg wrote:you're almost there! Run ant with the debug flag and you should see it extrapolate your exclude path....



I have run ant with the debug flag, but still can't understand why, I am sure that the exclude path is the right path

Can you see anything I am missing ?

Dani
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the full extrapolated path and does it match (with case sensitivity) the path you're expecting?
 
dani abdallah
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martijn Verburg wrote:What is the full extrapolated path and does it match (with case sensitivity) the path you're expecting?


Thanks Martin, I have managed to solve the exclude problem now, it was something to do with the path.
However unfortunately I still have a problem, as my .jar file is giving strange errors when I created a new project in my IDE and ran some tests.
My suspicion is that there is a problem with the compilation, as when I run ant in verbose mode I get, for example:

[javac] .....java added as ....class doesn't exist.


[javac] .....java added as ....class doesn't exist.

[javac] .....java added as ....class doesn't exist.


Does this mean for sure that it is not compiling correctly, as later down the log I get:

[javac] Files to be compiled:
[javac] ..../.../../*.java
[javac] ..../.../../*.java
[javac] / ..../.../../*.java


This is particularly confusing as it's my first experience of using ANT

Thanks again,

Dani
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a bit confused , so you run the ANT script inside eclipse to create the JAR file which now works fine. But when you run the ANT command to execute the tests it fails?

If that's the case then that kind of makes sense if you only have your JAR on the CLASSPATH and don't have the testclasses referenced on the CLASSPATH
 
dani abdallah
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martijn Verburg wrote:I'm a bit confused , so you run the ANT script inside eclipse to create the JAR file which now works fine. But when you run the ANT command to execute the tests it fails?

If that's the case then that kind of makes sense if you only have your JAR on the CLASSPATH and don't have the testclasses referenced on the CLASSPATH


I don't run the ant script inside eclipse, I create it from the terminal which creates a jar file for me. However, when testing the jar(as my goal is to allow users to add it to their library) by creating a new project in eclipse and adding my created jar to its library. I'm getting an error and the message "configure build path".

The build is always succesful and creates the .jar file, but I am thinking that maybe the source has not been compiled properly, hence the errors with the .jar file?

I've ran ant in verbose mode and got the results I showed in my previous post, although the build is succesful.

Thanks
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, not sure in that case, if you're installing the jar correctly into eclipse then you should be able to run client code against it.
 
dani abdallah
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martijn Verburg wrote:Hmm, not sure in that case, if you're installing the jar correctly into eclipse then you should be able to run client code against it.


Right, thanks anyway, you have been very helpful.

Regards,

Dani
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic