ClassNotFound exception on ClassLoader.loadClass method when the class is in different moduleAsk Questions

 Posted on 03/19/2019

I get ClassNotFound Exception in UserServiceApplication.kt file.

Below is my project structure.

Root Project | |---settings.gradle | |---common (library module) (Spring boot project) | | | |--build.gradle | |--src/main/kotlin/com/simbalarry/common/util/StringValidator.kt | |--src/main/kotlin/com/simbalarry/common/MainApp.kt | | |---user-manager (Spring boot project) (uses common) | |--build.gradle | |--src/main/kotlin/somepackage/UserServiceApplication.kt

Contents of all files RootProject/settings.gradle

include ':common', ':user-manager' = 'home-cuisine'


plugins { id 'java-library' id 'org.springframework.boot' version '2.1.3.RELEASE' id 'org.jetbrains.kotlin.jvm' version '1.2.71' id 'org.jetbrains.kotlin.plugin.spring' version '1.2.71' } apply plugin: 'io.spring.dependency-management' group = 'com.simbalarry' version = '0.0.1-SNAPSHOT' sourceCompatibility = '1.8' repositories { mavenCentral() } ext['kotlin.version'] = '1.2.71' dependencies { implementation 'org.jetbrains.kotlin:kotlin-reflect' implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' } compileKotlin { kotlinOptions { freeCompilerArgs = ['-Xjsr305=strict'] jvmTarget = '1.8' } }


package com.simbalarry.common.util class StringValidator { fun hello(): String { return "Bye" } }


package com.simbalarry.common class MainApp fun main(args: Array<String>) { }


plugins { id 'org.springframework.boot' version '2.1.3.RELEASE' id 'org.jetbrains.kotlin.jvm' version '1.2.71' id 'org.jetbrains.kotlin.plugin.spring' version '1.2.71' } apply plugin: 'io.spring.dependency-management' group = 'com.simbalarry' version = '0.0.1-SNAPSHOT' sourceCompatibility = '1.8' test { useJUnitPlatform() } repositories { mavenCentral() maven { url '' } maven { url '' } } dependencies { implementation project(':common') implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.jetbrains.kotlin:kotlin-reflect' implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' } compileKotlin { kotlinOptions { freeCompilerArgs = ['-Xjsr305=strict'] jvmTarget = '1.8' } }


package com.simbalarry.usermanager import com.simbalarry.common.util.StringValidator class UserServiceApplication fun main(args: Array<String>) { println("Hieex") val stringValidator = StringValidator() }

When I do gradle bootRun on the user-manager package, I get the following exception

E:\Repos\HC7\user-manager>gradle bootRun > Task :user-manager:bootRun FAILED Hieex Exception in thread "main" java.lang.NoClassDefFoundError: com/simbalarry/common/util/StringValidator at com.simbalarry.usermanager.UserServiceApplicationKt.main(UserServiceApplication.kt:9) Caused by: java.lang.ClassNotFoundException: com.simbalarry.common.util.StringValidator at at java.lang.ClassLoader.loadClass( at sun.misc.Launcher$AppClassLoader.loadClass( at java.lang.ClassLoader.loadClass( ... 1 more FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':user-manager:bootRun'. > Process 'command 'C:\Program Files\Java\jdk1.8.0_181\bin\java.exe'' finished with non-zero exit value 1 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See BUILD FAILED in 4s 4 actionable tasks: 1 executed, 3 up-to-date

Can anyone guide me what is going wrong with this project. I had this problem in bigger project but I have pasted the narrowed down problem here.

Share On: facebook gplus twitter
Asked by Jenish shah on 03/19/2019 Score: 17 points
Add Comment:


0 Answers

0 Corrected Answers

Post Your Answers

Existing Members

Sign in to your account
Email Address
...or Join us
Download, Vote, Comment, Publish.
Full Name
Email Address
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the StoodQ newsletters
Guideline to answer a question:

Useful tips to submit your answer
Please read below guidelines before you submit your answer for question.

  • Read and understand question for which you are submitting your answer.
  • Try to avoid grammatical and spell mistake while answering.
  • Do not post any irrelevant information in your answer.
  • Explain your answer with example or any reference link to help who posted question.
  • If you find irrelevant question, please report it to support. Click here to contact support.
  • You agree to the privacy policy and terms of use to submit any contents.

Note: StoodQ is online developers community which helps developer for their difficulty, lets help them with your value contribution.