cyberangles blog

How to Fix 'Class Not Found in Module' Warning When Creating IntelliJ Run/Debug Configuration for Java Application After BitBucket

If you’ve ever pulled code from BitBucket into IntelliJ IDEA and encountered the frustrating "Class Not Found in Module" warning when trying to run or debug your Java application, you’re not alone. This error typically arises when IntelliJ cannot locate the specified main class within your project’s module—often due to misaligned project structures, outdated dependencies, or IDE configuration issues after version control operations.

While this error can be perplexing, it’s rarely a dead end. In this guide, we’ll break down the root causes of the issue and walk through step-by-step solutions to resolve it. By the end, you’ll be able to configure your run/debug setup smoothly, even after syncing with BitBucket.

2026-02

Table of Contents#

  1. Understanding the "Class Not Found in Module" Error
    • What Does the Error Mean?
    • Why Does It Occur After BitBucket Operations?
  2. Common Causes of the Error
    • Module Configuration Issues
    • Build Tool and Dependency Sync Problems
    • IntelliJ Cache Corruption
    • Incorrect Run Configuration Settings
    • Version Control Conflicts
  3. 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
  4. Preventive Measures to Avoid Future Errors
  5. Conclusion
  6. 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., .iml files) might change, leaving IntelliJ out of sync.
  • Merging branches: Conflicts in critical files (like pom.xml or .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:

  1. Go to Build > Rebuild Project (or press Ctrl+Shift+F9 on Windows/Linux, Cmd+Shift+F9 on Mac).
  2. 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#

  1. Open File > Project Structure (shortcut: Ctrl+Alt+Shift+S on Windows/Linux, Cmd+; on Mac).

  2. Go to Modules (left sidebar). Select your project module (e.g., my-app).

  3. In the right panel, check the Sources tab. Ensure src/main/java is marked as a Sources root (blue folder icon). If not:

    • Right-click src/main/java > Mark Directory as > Sources Root.

    Verify Source Roots in IntelliJ
    [Note: Replace with a screenshot of IntelliJ’s Project Structure > Modules > Sources tab showing src/main/java as a Sources root.]

Step 2: Repair Corrupted .iml Files#

IntelliJ stores module settings in .iml files (e.g., my-app.iml). If BitBucket corrupted this file:

  1. Close IntelliJ.
  2. In your project folder, delete the .iml file for your module (e.g., my-app.iml).
  3. Reopen IntelliJ. It will auto-regenerate the .iml file. If not, right-click the project root > Add Framework Support and 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:#

  1. Right-click your pom.xml file in the Project Explorer.

  2. Select Maven > Reload Project.

    Maven Reload Project
    [Note: Replace with a screenshot of the Maven > Reload Project option.]

For Gradle Projects:#

  1. Open the Gradle tool window (right sidebar).
  2. 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:

  1. Go to File > Invalidate Caches…

  2. Select Invalidate and Restart (this will close and reopen IntelliJ).

    Invalidate Caches
    [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#

  1. Open the run/debug dropdown (top-right IntelliJ) > Edit Configurations….
  2. Select your Java application configuration (or click + > Application to create a new one).

Step 2: Verify Key Settings#

  • Main class: Ensure the full class path is correct (e.g., com.example.MyApplication, not just MyApplication). Use the Browse button 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).

    Correct Run Configuration
    [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:

  1. Open the Version Control tool window (bottom-left, or Alt+9).
  2. Go to the Merge Conflicts tab. Right-click conflicting files (e.g., pom.xml) > Resolve Conflicts.
  3. Use IntelliJ’s merge tool to select the correct version (e.g., "Accept Yours" or "Accept Theirs") and save.
  4. 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:

  1. Open File > Project Structure > Modules.

  2. Select your module, then go to the Dependencies tab.

  3. Under Module SDK, ensure a valid JDK is selected (e.g., corretto-17). If none is listed:

    • Click Add SDK > JDK and point to your JDK installation folder (e.g., C:\Program Files\Java\jdk-17).

    Module SDK Setup
    [Note: Replace with a screenshot of the Dependencies tab showing a valid SDK.]

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:

  1. Close IntelliJ.
  2. In your project folder, delete the .idea folder and any .iml files (these store IntelliJ-specific settings and can be regenerated).
  3. Reopen IntelliJ > Open > Select your project root (e.g., my-app).
  4. 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 .iml and build files carefully: Avoid manually editing .iml files (let IntelliJ manage them). If using Git, include .iml in your repo to ensure consistent module setups across team members.
  • Sync build tools after pulls: Always run Maven > Reload Project or Gradle > Sync after 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.

References#