{"id":3638,"date":"2019-07-21T04:33:08","date_gmt":"2019-07-21T04:33:08","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=3638"},"modified":"2024-12-07T14:59:54","modified_gmt":"2024-12-07T14:59:54","slug":"how-to-fix-invalidmoduledescriptorexception","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/how-to-fix-invalidmoduledescriptorexception\/","title":{"rendered":"How to fix  InvalidModuleDescriptorException"},"content":{"rendered":"<h2>How to fix InvalidModuleDescriptorException<\/h2>\n<p>The exception java.lang.module.InvalidModuleDescriptorException is caused by an unnamed package not allowed in a module.<\/p>\n<h3>Error<\/h3>\n<pre>Error occurred during initialization of boot layer\r\njava.lang.module.FindException: Error reading module: \r\nF:\\eclipse-workspace\\Sample\\bin\r\nCaused by: java.lang.module.InvalidModuleDescriptorException: \r\nSampleClass.class found in top-level directory (unnamed package not allowed \r\nin module)<\/pre>\n<p>&nbsp;<\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3647\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InvalidModuleDescriptorException.png\" alt=\"InvalidModuleDescriptorException\" width=\"1920\" height=\"1031\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InvalidModuleDescriptorException.png 1920w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InvalidModuleDescriptorException-300x161.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InvalidModuleDescriptorException-1024x550.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InvalidModuleDescriptorException-768x412.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/InvalidModuleDescriptorException-1536x825.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/h3>\n<h2>Fixes<\/h2>\n<p>Check the JDK version of the project. InvalidModuleDescriptorException is a runtime exception usually thrown when reading module descriptor.<\/p>\n<h3># Refactor the code<\/h3>\n<p>If we want the project to be as Java module, then we need to refactor the code. The above error occurs when Java classes are created right under the default <strong>src<\/strong> default package folder. The unnamed package is not allowed in the module with the latest JDK.<\/p>\n<p>We must declare a named package because this compilation unit is associated to the named module.The name of the module can be found in <strong>module-info.java<\/strong> during the project creation phase. To avoid this kind of exception, move all the classes that are in the default package to some named packages.<\/p>\n<p><strong>Create a Package.<\/strong><\/p>\n<p>Steps to create a new package in Eclipse IDE<\/p>\n<p><a href=\"https:\/\/www.testingdocs.com\/questions\/how-to-create-a-package-in-eclipse-ide\/\">https:\/\/www.testingdocs.com\/questions\/how-to-create-a-package-in-eclipse-ide\/<\/a><\/p>\n<p>Refactor the code to move the classes in unnamed packages to named ones.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3648\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Java-Error-.png\" alt=\"Java Exception Fix\" width=\"1920\" height=\"989\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Java-Error-.png 1920w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Java-Error--300x155.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Java-Error--1024x527.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Java-Error--768x396.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Java-Error--1536x791.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3># Module descriptor file<\/h3>\n<p>If you still see the error:<\/p>\n<p>Check the module descriptor file <strong>module-info.java . <\/strong>This file contains the metadata for the module dependencies, packages exports, etc.<\/p>\n<h3># Not a Java Module<\/h3>\n<p>If we don&#8217;t want the project to be a Java module then simply delete the <strong>module-info.java<\/strong> module descriptor file to fix this error.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to fix InvalidModuleDescriptorException The exception java.lang.module.InvalidModuleDescriptorException is caused by an unnamed package not allowed in a module. Error Error occurred during initialization of boot layer java.lang.module.FindException: Error reading module: F:\\eclipse-workspace\\Sample\\bin Caused by: java.lang.module.InvalidModuleDescriptorException: SampleClass.class found in top-level directory (unnamed package not allowed in module) &nbsp; Fixes Check the JDK version of the project. InvalidModuleDescriptorException [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3638","post","type-post","status-publish","format-standard","hentry","category-automation","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=3638"}],"version-history":[{"count":17,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3638\/revisions"}],"predecessor-version":[{"id":26287,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3638\/revisions\/26287"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=3638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=3638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=3638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}