Saturday 18 February 2017

Eclipse error: Could not find or load main class com.sun.tools.internal.xjc.XJCFacade

Could not find or load main class com.sun.tools.internal.xjc.XJCFacade


Problem: When I right click a schema file and choose "Generate" and "JAXB Classes", I see the following stack trace in then console:

"java.lang.NoClassDefFoundError: com/sun/tools/xjc/XJCFacade
Caused by: java.lang.ClassNotFoundException: com.sun.tools.xjc.XJCFacade"

Could not find or load main class com.sun.tools.internal.xjc.XJCFacade


Solution: When eclipse project libraries are not pointing to JDK, and instead it is pointing to the JRE, you will get this error "Error: Could not find or load main class com.sun.tools.internal.xjc.XJCFacade". If the JDK path was not configured in your installed JRE's please do the following.

Go to Window -> Preferences, Select Installed JREs. Click on Add and select Standard VM and click Next.

Could not find or load main class com.sun.tools.internal.xjc.XJCFacade 

Could not find or load main class com.sun.tools.internal.xjc.XJCFacade

Select JDK installation directory and click on Finish.

Could not find or load main class com.sun.tools.internal.xjc.XJCFacade

Once you clicked finish button, the JDK entry will be shown in the Installed JREs window. Now select the newly added path and click OK. Eclipse will build all your project.

Could not find or load main class com.sun.tools.internal.xjc.XJCFacade

Now select the xsd file and generate the JAXB classes, it will generate the classes successfully without any error.

17 comments:

  1. Thanks for the post, But I am facing the same issue after the JDK Added.

    ReplyDelete
  2. java.xml.bind was deprecated in 9

    ReplyDelete
  3. i changed jre to jdk, Still problems away

    ReplyDelete
  4. Thanks!

    To those who still getting error, check in the "Console" tab, because maybe you are still using the old jre instead of the "jdk1.8.0_111\bin\javaw.exe".

    ReplyDelete
  5. This helped me:
    Window -> Preferences -> Java -> Installed JREs -> Ececution Environments -> JavaSe-1.8 -> Check the jdk box

    Hope it helps

    ReplyDelete
    Replies
    1. Worked for me! Thanks

      Delete
    2. Worked also for me! Thanks!

      Delete
    3. That's great!! Thanks

      Delete
  6. works for me. thanks

    ReplyDelete
  7. Thanks. Additionally, I had to remove the current project runtime that was a JRE and replace it with the JDK.

    ReplyDelete
  8. above solution helped

    ReplyDelete
  9. Thank you. After changing to JDK it worked for me.

    ReplyDelete