Related: How can I compile "import pack. *" With ant / javac if there are no such classes?
Suppose we have a given packing structure
parent |
where the parent package contains only two subpackages a and b (the class is not under the parent package).
The import parent.* Code, located in a package other than parent , compiled with Maven (i.e. javac ) throws a compile-time error. Error:
package parent does not exist
I studied the Java language specification in this case (on-demand import declaration, where types are not actually imported). Paragraph 7.5.2 of the JLS on declaring import on demand does not seem to indicate this behavior.
Is this a javac bug? I am not asking how to get around a compilation error. I would like to know why javac throws an error, because I cannot find the link in JLS, that it should; making me believe that this could be a mistake.
I tested with JDK 1.4, 1.6, 1.7 and 1.8, the error is the same.
As a side note, Eclipse lacks compilation with the same code (tested with Eclipse Indigo, Juno, Luna, and Mars).
NB: I encountered this behavior when “mavenizing” an (old) existing project that relied only on the Eclipse compiler. It took me a while to determine that this was the main cause of the compilation error I was getting.
source share