1

enter image description hereToday 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>
Syed
  • 2,471
  • 10
  • 49
  • 89
  • I guess this is a multi-module maven project. If you want to open a class of a module you need to open the class in the `sub-module` not in `parent->sub-module`. You can check the icon of the editor. If it's a solid `J` then it's correct. If it's a framed `J` you oen the class at the wrong place. – SubOptimal Jun 14 '16 at 06:15
  • @SubOptimal, few auto suggestion is working and few are not working.. For eg, Syso -> System.out.println is coming now, where as if I want to see the methods of the objects, even after pressing ctrl + space, methods are not coming – Syed Jun 14 '16 at 06:39
  • the explanation for this is that `System` and its methods are part of Java SE – JimHawkins Jun 14 '16 at 06:44
  • What structure does your project have? Do you see the solid `J` on the editor tab? Auto-completion of `syso` is an Eclipse editor thing. If your class is not found it's an classpath related thing. Are your sources below `src/main/java`. What is your directory structure? You should add more information. – SubOptimal Jun 14 '16 at 06:44
  • @SubOptimal, uploaded the screen shot of Java classes. – Syed Jun 14 '16 at 06:45
  • please post your `pom.xml` – JimHawkins Jun 14 '16 at 06:46
  • did you use the m2e plugin? I guess no – JimHawkins Jun 14 '16 at 06:48
  • @Ulrich, updated with pom.xml – Syed Jun 14 '16 at 06:49
  • Can you see in your screenshot that it's a framed `J` you need to open the files from a different path. As I said already. – SubOptimal Jun 14 '16 at 06:49
  • @SubOptimal, How can I open them in different path? I didn't understand what you said – Syed Jun 14 '16 at 06:50
  • your screenshot indicates that you are working with a multi module project, as @Syed already assumed. How did you import it to eclipse? – JimHawkins Jun 14 '16 at 06:51
  • Have a look at `http://help.eclipse.org/luna/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/ref-icons.htm`. – SubOptimal Jun 14 '16 at 06:51
  • @Ulrich, as normal fashion only File->import-> Existing maven projects, then point to the folder where it is located. – Syed Jun 14 '16 at 06:52
  • @SubOptimal, the topic isn't available – Syed Jun 14 '16 at 06:53
  • try [this](http://help.eclipse.org/luna/topic/org.eclipse.jdt.doc.user/reference/ref-icons.htm?cp=1_4_12) – JimHawkins Jun 14 '16 at 06:57
  • @SubOptimal, what should be done for this fix? – Syed Jun 14 '16 at 06:58

2 Answers2

2

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.

1

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 enter image description here
solid J icon enter image description here

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 documentationImporting Maven Projects.

SubOptimal
  • 22,518
  • 3
  • 53
  • 69
  • All my sub modules are having same icon – Syed Jun 14 '16 at 06:59
  • Tell me the correct process of importing Maven project, I've downloaded the project from SVN and stored them in E drive, and my workspace is in F drive – Syed Jun 14 '16 at 07:00
  • @Syed I added a link with a description. You need the m2e plugin and then the project must be imported as described at the link. Maybe at this step there was a mistake. – SubOptimal Jun 14 '16 at 07:21
  • I can't open that link as its blocked here – Syed Jun 14 '16 at 07:37
  • @Syed Than search in the internet for `importing maven projects into eclipse`. – SubOptimal Jun 14 '16 at 10:06