Hi, I've found the reason: JAVA rejects import statements that import a type from the unnamed namespace since v1.4.
See also: http://java.sun.com/javase/compatibility_j2se1.4.html#incompatibilities1.4 -----邮件原件----- 发件人: 汪燕青 [mailto:wangyanq...@gameabc.com] 发送时间: 2011年3月22日 10:48 收件人: Ant Users List 主题: 答复: javac task encountered a compiling error at the 'import' statement I've tried setting the classpath and sourcepath, still didn't work. But if I removed the problematic import statement, compiling ok, which means the classpath and sourcepath is right. It seems like JAVA forbids this kind of import -- the class to be imported has to have at least 1 prefix. But I when using Eclipse, setting the project's java compiler's 'Compiler compliance level' to 1.3, it was ok. -----邮件原件----- 发件人: 汪燕青 [mailto:wangyanq...@gameabc.com] 发送时间: 2011年3月22日 10:20 收件人: Ant Users List 主题: 答复: javac task encountered a compiling error at the 'import' statement Of course Scot. See the attachement. -----邮件原件----- 发件人: Scot P. Floess [mailto:sflo...@nc.rr.com] 发送时间: 2011年3月22日 10:20 收件人: Ant Users List 主题: Re: javac task encountered a compiling error at the 'import' statement Can we see your build.xml? Sounds like a classpath/srcpath issue... On Tue, 22 Mar 2011, 汪燕青 wrote: > > Hi everyone, > > > > When I’m building a simple project with ANT 1.8.2, I encountered a compiling > error at the import statement of the java code file. > > There only 2 java files: A.java and com/B.java. > > A.java is in the root dir of the source directory, it has a public > static method test() that B.java will call; > > B.java is in the package com, it calls A.test() from inside, with > ‘import A;’ at the beginning following ‘package com;’. > > > > When I wrote a build.xml and added a <javac> task in it to > compile the java codes, there appeared a compiling error at the ‘import’ > statement ---- ‘.’ needed ---- seems that can’t import the class at the root > of the source directory in JAVA. > > But it runs well when I put the codes in Eclipse. And I tried > all the attributes of the javac task but still didn’t work. I don’t know why. > > > > Anyone faced the similar problem? How did you solve this? > > Any suggestions would be highly appreciated! > > > > > > > > The Eclipse project’s Java compiler setting is like this: > > cid:image001.png@01CBE808.BD0895F0 > > > > And I set the javac task’s source=”1.3” and target=”1.1”: > > <javac source="1.3" target="1.1" srcdir="src" destdir="class"/> > > Will get the same error. > > > > > > > -- Scot P. Floess RHCT (Certificate Number 605010084735240) Chief Architect FlossWare http://sourceforge.net/projects/flossware http://flossware.sourceforge.net https://github.com/organizations/FlossWare