Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

339
Views
java.lang.ClassNotFoundException when running in IntelliJ IDEA

I creating a program to work with databases and I am getting the following error when compiling in IntelliJ IDEA. Does anyone why this is happening and how I could solve it?

enter image description here

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The error that you get occurs not on complilation, but when you try to run your application. It happens because Java was not able to find Table.class file inside db subdirectory of the project output directory (classpath).

It can happen for multiple reasons:

  • wrong main class selected in the run/debug configuration
  • Table.java is excluded from compilation (by accident or intentionally because it contained errors and you wanted to skip it while working on other code)
  • class not compiled because Build step is excluded from from Before launch steps in the Run/Debug configuration
  • project is misconfigured and there is no Source root defined for the directory containing db subdirectory
  • Table.java has incorrect package statement or is located/moved to a different package
  • project path contains a colon : on Mac/Linux or semicolon ; on Windows, it's used to separate the classpath and will render the classpath invalid. See this thread for details. Note that Finder on Mac may display colons in the path as slashes.
  • the jar may not execute if one of the dependent jars is digitally signed since the new artifact will include the partial signature of the dependency. See this answer for more details.
  • In project structure make sure you have the right Java version for compile.
  • there is a known bug that sometimes a Java project created from the Command Line template doesn't work because .idea/modules.xml file references invalid module file named untitled104.iml. Fix the module name manually or create a project from scratch and don't use a template.
  • on Windows "Beta: Use Unicode UTF-8 for worldwide language support" Region Setting is enabled. See IDEA-247837 for more details and workarounds.
  • When IntelliJ IDEA is configured to store module dependencies in Eclipse format source root configuration is lost due to a known bug. Configure the module to use IntelliJ IDEA format dependencies as a workaround.

In a properly configured project and with the correct run/debug configuration everything works just fine:

Run

about 4 years ago · Santiago Trujillo Report

0

  • the jar may not execute if one of the dependent jars is digitally signed since the new artifact will include the partial signature of the dependency. See this answer for more details.

I must again emphasis the point CrazyCoder has here.

The (Oracle) JVM used to throw a SecurityException when you tried to run a Jar-File containing broken signatures. This made sense from a "What's wrong"-Point of view.

That is no longer the case. They are indeed throwing ClassNotFoundExceptions now - even if the class is right there in the file (no matter if it is in the default package/toplevel or way down in a nested package structure).

about 4 years ago · Santiago Trujillo Report

0

Here's what worked for me:

I deleted .ide folder, .iml file. And all other auto generated files by intelliJ then restarted my ide and I was asked if I want to make my project run with maven that's it.

Obviously I said yes :)

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!