How to compile only specific .java files, not the whole src
dani abdallah
Greenhorn
Joined: Jul 12, 2010
Posts: 13
posted
0
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?
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.
(I assume you're asking a question about Ant, and not something else?)
dani abdallah
Greenhorn
Joined: Jul 12, 2010
Posts: 13
posted
0
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:
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?
If you have different *packaging* requirements, that would be best handled during the packaging part of things.
dani abdallah
Greenhorn
Joined: Jul 12, 2010
Posts: 13
posted
0
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?
What is the full extrapolated path and does it match (with case sensitivity) the path you're expecting?
dani abdallah
Greenhorn
Joined: Jul 12, 2010
Posts: 13
posted
0
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
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
Joined: Jul 12, 2010
Posts: 13
posted
0
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.
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
Joined: Jul 12, 2010
Posts: 13
posted
0
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
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: How to compile only specific .java files, not the whole src