• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

javac in ant, please helppp

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, i got a 'slight' problem here using ant. I tried to compile a class, let's call it A.java, in a dir /home/test/a/b/c. and the A.java contains import b.B; B.java itself is at another dir, ... let's say /home/test/b, like this :
/home/test/a/b/c/A.java -> import b.B;
/home/test/b/B.java -> package b;
Using command line javac, i must use -classpath option in order to compile class A.java successfully
~/a/b/c> javac -classpath /home/test:. A.java
The result is that B.java was compiled first, and then A.java.
if i use my build.xml and ant to compile A.java, it will always generate errors :
Buildfile: build.xml
compile:
[javac] Compiling 1 source file
[javac] /home/moonblade/devel/test/packageTest/A.java:1: package a does not exist
[javac] import a.*;
[javac] ^
[javac] /home/moonblade/devel/test/packageTest/A.java:5: cannot resolve symbol
[javac] symbol : variable B
[javac] location: class A
[javac] B.test();
[javac] ^
[javac] 2 errors
The behaviour i want is that B is compiled first AUTOMATICALLY without the task's depends attribute, just like the command line javac did. But from the err msg i got, it seems that ant couldnt compile A.java because B.class doesnt exist. The ant works out fine if the B.class exists. And i really need to use ant for other purposes, so plz dont suggest me to use javac command line instead
Here is my VERY simple build.xml :
<project name="test" basedir="." default="compile">
<path id="compile.classpath">
<pathelement location="/home/test"/>
</path>
<!-- Check timestamp on files -->
<target name="prepare">
<tstamp/>
</target>
<target name="compile">
<javac srcdir=".">
<classpath refid="compile.classpath"/>
</javac>
</target>
</project>
Can anybody help me out ? :roll:
 
Albert Gan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, maybe my explanation in previous posting was pretty confusing
I'll try to make my problem simpler to understand:
I just want make sure of something. If Ant is told to compile a source, that imports other sources/packages that havent been compiled, can it also automatically compile those that havent been compiled like the ordinary 'javac' command does?
I still couldnt have it solved, so really need your opinions ..
pleaseeeeeeeeee
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think for this to work you need to reference the other classpath as sourcedir too.
Try this:

Then both dirs gets treated as source dirs and classes get recompiled.
 
Do you pee on your compost? Does this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic