简体   繁体   中英

The compilation unit is not on the build path of a Java project - Maven

在此处输入图片说明 Today I've imported a Maven project in my eclipse. When I try to go for Auto suggest, when I was adding some code, it alerts me as "The compilation unit is not on the build path of a Java project". I saw few workarounds for this issue, but none of them solved. What should be done for this one?

  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>com.core.extension</groupId>
    <artifactId>Softpro</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>cu-softpro-connector</artifactId>
<name>jar :: cu-softpro-connector</name>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>com.core.extension</groupId>
        <artifactId>cu-softpro-client</artifactId>
    </dependency>
    <dependency>
        <groupId>com.core.framework</groupId>
        <artifactId>cu-svcframework-ejb</artifactId>
        <type>ejb</type>
    </dependency>
    <dependency>
        <groupId>com.core.framework</groupId>
        <artifactId>cu-shared</artifactId>
    </dependency>
    <dependency>
        <groupId>com.core.base</groupId>
        <artifactId>cu-common-entity</artifactId>
    </dependency>
    <dependency>
        <groupId>com.core.base</groupId>
        <artifactId>cu-services-base</artifactId>
        <exclusions>
            <exclusion>
                <groupId>com.core.framework</groupId>
                <artifactId>cu-subsystems</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.core.base</groupId>
        <artifactId>cu-platform-model</artifactId>
    </dependency>
    <dependency>
        <groupId>com.core.extension</groupId>
        <artifactId>cu-forms-connector</artifactId>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-core</artifactId>
    </dependency>
</dependencies>
</project>

I was facing the same issue with the maven project when I imported.

Root Cause:

I Searched the file by pressing Ctrl+Shift+R and open the file on the path on the Parent -> Sub-module -> FileName.java .So while pressing Ctrl+Space it was giving the error The compilation unit is not on the build path of a Java project - Maven

Solution:

We need to make sure that we are opening the file on the submodule path and also the build path should be configure to the proper jdk installed in your project.

Hope this helps.

When you open a multi-module Maven project in Eclipse you see in the project explorer normally

- parent-module
  - sub-module1
    - src
      - main
        - java
          - YourClass <-- the one with the framed J icon
  + sub-module2
- sub-module1
  - src
    - main
      - java
        - YourClass <-- the one with the solid J icon

framed J icon在此处输入图片说明
solid J icon在此处输入图片说明

Icons are explained at http://help.eclipse.org/luna/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/ref-icons.htm .

To import a Maven project into Eclipse follow this documentation Importing Maven Projects .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM