Why Do I Get a Build Error When Including javax.* Source In My Project?

If you attempt to add java.* or javax.* classes to your project from other sources (e.g., Apache Harmony), you will likely get the following error message in your build:

Attempt to include a core VM class in something other than a core library.
It is likely that you have attempted to include the core library from a desktop
virtual machine into an application, which will most assuredly not work. If
you really intend to build a core library -- which is only appropriate as
part of creating a full virtual machine binary, as opposed to compiling an
application -- then use the "--core-library" option to suppress this error
message. If you go ahead and use "--core-library" but are in fact building
an application, then please be aware that your build will still fail at some
point; you will simply be denied the pleasure of reading this helpful error

In a nutshell, you cannot do what you are trying to do.

One workaround is to find the places that reference the class(es) you are trying to add. If the "touch points" are few in number, you may be able to put the java.*/javax.* classes in another namespace and patch up the references to them.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License