Table of Contents#
- Understanding the "Class Not Found in Module" Error
- What Does the Error Mean?
- Why Does It Occur After BitBucket Operations?
- Common Causes of the Error
- Module Configuration Issues
- Build Tool and Dependency Sync Problems
- IntelliJ Cache Corruption
- Incorrect Run Configuration Settings
- Version Control Conflicts
- Step-by-Step Solutions to Fix the Error
- Preliminary Check: Rebuild the Project
- Solution 1: Verify Module Structure and Source Roots
- Solution 2: Sync Build Tools (Maven/Gradle)
- Solution 3: Invalidate IntelliJ Caches and Restart
- Solution 4: Correct Run Configuration Settings
- Solution 5: Resolve Version Control Conflicts
- Solution 6: Check SDK and JDK Configuration
- Solution 7: Reimport the Project
- Preventive Measures to Avoid Future Errors
- Conclusion
- References
Understanding the "Class Not Found in Module" Error#
What Does the Error Mean?#
The "Class Not Found in Module" warning in IntelliJ appears when you attempt to run a Java application, and the IDE cannot locate the specified main class within the selected module. The error message typically looks like this:
Error: Could not find or load main class com.example.MyApplication
Caused by: java.lang.ClassNotFoundException: com.example.MyApplication
This means IntelliJ’s run/debug configuration is pointing to a class that either:
- Doesn’t exist in the project,
- Isn’t compiled (due to errors or missing dependencies), or
- Isn’t properly mapped to the project’s module structure.
Why Does It Occur After BitBucket Operations?#
BitBucket (or any version control system) can disrupt your project’s setup in subtle ways, including:
- Cloning a new repository: IntelliJ may not auto-configure modules/source roots correctly.
- Pulling updates: Dependencies, build files (e.g.,
pom.xml,build.gradle), or module settings (e.g.,.imlfiles) might change, leaving IntelliJ out of sync. - Merging branches: Conflicts in critical files (like
pom.xmlor.iml) can corrupt project structure. - Checking out an older commit: Outdated code may reference classes or dependencies no longer present.
Common Causes of the Error#
To fix the issue, we first need to identify why IntelliJ can’t find the class. Here are the most likely culprits after BitBucket interactions:
1. Module Configuration Issues#
IntelliJ relies on module settings (stored in .iml files) to map code to projects. If BitBucket overwrites, corrupts, or omits these files (e.g., during a merge), the module may lose track of source roots (e.g., src/main/java).
2. Build Tool and Dependency Sync Problems#
If your project uses Maven or Gradle, BitBucket may pull updates to pom.xml or build.gradle (e.g., new dependencies or version changes). If IntelliJ doesn’t sync these changes, required libraries (and thus classes) may be missing.
3. IntelliJ Cache Corruption#
IntelliJ caches project data to improve performance, but these caches can become stale after code changes from BitBucket. Outdated caches may cause IntelliJ to "forget" newly added or modified classes.
4. Incorrect Run Configuration Settings#
Even if your project is intact, a misconfigured run/debug setup (e.g., selecting the wrong module, misspelling the main class path, or using an outdated class reference) will trigger the error.
5. Version Control Conflicts#
Merge conflicts in BitBucket can alter critical files like pom.xml, build.gradle, or .iml, breaking dependencies or module structure. For example, a conflict in pom.xml might remove a required dependency.
Step-by-Step Solutions to Fix the Error#
Follow these steps in order to systematically resolve the "Class Not Found in Module" warning.
Preliminary Check: Rebuild the Project#
Before diving into configurations, ensure your code compiles. A failed build will prevent classes from being generated, leading to "Class Not Found" errors.
How to do it:
- Go to
Build > Rebuild Project(or pressCtrl+Shift+F9on Windows/Linux,Cmd+Shift+F9on Mac). - Check the Problems tab (bottom of IntelliJ) for compilation errors. Fix any issues (e.g., missing imports, syntax errors) before proceeding.
Solution 1: Verify Module Structure and Source Roots#
If your module’s source roots (e.g., src/main/java) aren’t marked correctly, IntelliJ won’t recognize your main class. This is common after BitBucket overwrites .iml files.
How to fix it:
Step 1: Check Source Roots#
-
Open
File > Project Structure(shortcut:Ctrl+Alt+Shift+Son Windows/Linux,Cmd+;on Mac). -
Go to
Modules(left sidebar). Select your project module (e.g.,my-app). -
In the right panel, check the Sources tab. Ensure
src/main/javais marked as a Sources root (blue folder icon). If not:- Right-click
src/main/java>Mark Directory as > Sources Root.

[Note: Replace with a screenshot of IntelliJ’s Project Structure > Modules > Sources tab showing src/main/java as a Sources root.] - Right-click
Step 2: Repair Corrupted .iml Files#
IntelliJ stores module settings in .iml files (e.g., my-app.iml). If BitBucket corrupted this file:
- Close IntelliJ.
- In your project folder, delete the
.imlfile for your module (e.g.,my-app.iml). - Reopen IntelliJ. It will auto-regenerate the
.imlfile. If not, right-click the project root >Add Framework Supportand reselect your build tool (Maven/Gradle).
Solution 2: Sync Build Tools (Maven/Gradle)#
After pulling from BitBucket, your pom.xml (Maven) or build.gradle (Gradle) may have new dependencies. IntelliJ needs to download these to compile your code.
For Maven Projects:#
-
Right-click your
pom.xmlfile in the Project Explorer. -
Select
Maven > Reload Project.
[Note: Replace with a screenshot of the Maven > Reload Project option.]
For Gradle Projects:#
- Open the Gradle tool window (right sidebar).
- Click the Sync button (refresh icon) or right-click your project >
Reload Gradle Project.
Why this works: Syncing ensures IntelliJ downloads missing dependencies and updates the project classpath.
Solution 3: Invalidate Caches and Restart#
Stale caches are a frequent culprit. Invalidate IntelliJ’s caches to force it to rebuild project data from scratch.
How to do it:
-
Go to
File > Invalidate Caches… -
Select
Invalidate and Restart(this will close and reopen IntelliJ).
[Note: Replace with a screenshot of the Invalidate Caches dialog.]
Why this works: Caches store old project metadata. Invalidating them clears outdated references to classes or modules.
Solution 4: Correct Run Configuration Settings#
A misconfigured run/debug setup is often the root cause. Verify your settings:
Step 1: Create/Edit the Run Configuration#
- Open the run/debug dropdown (top-right IntelliJ) >
Edit Configurations…. - Select your Java application configuration (or click
+ > Applicationto create a new one).
Step 2: Verify Key Settings#
-
Main class: Ensure the full class path is correct (e.g.,
com.example.MyApplication, not justMyApplication). Use theBrowsebutton to auto-select the class from your project. -
Use classpath of module: Select the correct module (matches your project’s main module, e.g.,
my-app). -
Working directory: Ensure it points to your project root (e.g.,
~/projects/my-app).
[Note: Replace with a screenshot of a valid run configuration.]
Solution 5: Resolve Version Control Conflicts#
If BitBucket merge conflicts altered critical files (e.g., pom.xml, .iml), resolve them to restore project structure.
How to do it:
- Open the Version Control tool window (bottom-left, or
Alt+9). - Go to the Merge Conflicts tab. Right-click conflicting files (e.g.,
pom.xml) >Resolve Conflicts. - Use IntelliJ’s merge tool to select the correct version (e.g., "Accept Yours" or "Accept Theirs") and save.
- After resolving, re-sync your build tool (Maven/Gradle) as in Solution 2.
Solution 6: Check SDK and JDK Configuration#
IntelliJ needs a valid JDK to compile Java classes. If the module’s SDK is missing or outdated, classes won’t compile.
How to fix it:
-
Open
File > Project Structure > Modules. -
Select your module, then go to the Dependencies tab.
-
Under
Module SDK, ensure a valid JDK is selected (e.g.,corretto-17). If none is listed:- Click
Add SDK > JDKand point to your JDK installation folder (e.g.,C:\Program Files\Java\jdk-17).

[Note: Replace with a screenshot of the Dependencies tab showing a valid SDK.] - Click
Solution 7: Reimport the Project#
If all else fails, reimporting the project forces IntelliJ to reset its configuration based on your codebase.
How to do it:
- Close IntelliJ.
- In your project folder, delete the
.ideafolder and any.imlfiles (these store IntelliJ-specific settings and can be regenerated). - Reopen IntelliJ >
Open> Select your project root (e.g.,my-app). - When prompted, select "Import as Maven/Gradle project" (depending on your build tool).
Preventive Measures to Avoid Future Errors#
To minimize "Class Not Found" issues after BitBucket operations:
- Commit
.imland build files carefully: Avoid manually editing.imlfiles (let IntelliJ manage them). If using Git, include.imlin your repo to ensure consistent module setups across team members. - Sync build tools after pulls: Always run
Maven > Reload ProjectorGradle > Syncafter pulling from BitBucket. - Resolve conflicts immediately: Don’t ignore merge conflicts in
pom.xml,build.gradle, or.iml—they break project structure. - Update IntelliJ: Newer versions fix bugs related to module detection and cache handling.
Conclusion#
The "Class Not Found in Module" warning in IntelliJ after BitBucket operations is rarely caused by a single issue—it’s often a mix of misconfiguration, outdated caches, or sync problems. By systematically checking module structure, syncing dependencies, invalidating caches, and verifying run settings, you can resolve the error quickly.
Remember: Start with the basics (rebuild the project, check source roots) before moving to advanced fixes (reimporting the project). With these steps, you’ll have your Java application running smoothly in no time.