This program:
import foo.bar.baz.ClassSpecificallyIncluded;
import javax.xml.bind.JAXBContext;
public class A {
public static void main(String[]
The answer to your question is effectively answered here:
Can you find all classes in a package using reflection?
Answer: No By design, java doesn't know and can't find every class in a package. Java is built on the concept of "Just in time". Which for this purpose means that java doesn't know what it's got until it's asked for something specifically.
So from that stand point, JAXB has no way to find what classes are in a package.
It would be inconvenient if JAXB had to be told precisely every class every time you needed context. So as a convenience method JAXB offers you the option of providing a package name.
In order to get round the limitations of java it attempts to load from that package an ObjectFactory
and a jaxb.index
file. It can do this because they are specific names. If one is found, then it uses them as a manifest for the package. If neither is found it has no option but to abort because it can't possibly know what's in the package.