0

I am working on Spring boot application with different project structure please find the attached screenshot.
enter image description here
When I go to eclipse and select Run as --> Maven Build with 'clean install' command it gives below error:

**[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/UserName/Downloads/project-api/src/main/java/com/project/api/dto/APIDto.java:[6,35] package com.project.publicapi.dto does not exist**

As classes under src/public/java folder which contains package com.project.publicapi.dto is not compiled.

I have tried to build explicitly and run the project it works. But while building with maven the compilation fails with above mentioned error.

Any suggestion.

Below is the pom file.

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>project-api</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>[2.0.0]</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.14</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <id>spring-releases</id>
        <url>http://repo.spring.io/libs-release</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <url>http://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

Dipan
  • 301
  • 2
  • 7
  • Compilation error while building ... when else would you get a compilation error? package com.project.publicapi.dto does not exist** This can be caused by a missing dependency or wrong version. You only give very limited information, and a very limited part of the stacktrace. You'll need to be more clear – Stultuske Jun 27 '18 at 06:43
  • @Stultuske, I have 2 folders src/main/java and src/public/java, while building it gives the above mentioned error as one of the class under src/main/java is not able to find the class under src/public/java as it is not compiled by maven compile phase. – Dipan Jun 27 '18 at 07:01
  • [ERROR] /C:/Users/UserName/Downloads/project/api/src/main/java/com/project/api/dto/APIDto.java:[46,22] cannot find symbol symbol: class GetEventDto **(this class is under src/public/java folder)** location: class com.project.api.dto.APIDto – Dipan Jun 27 '18 at 07:02
  • 1
    When executing the pure maven build you need to facilitate the maven-build-helper plugin to add non-standard source folders as described here: https://stackoverflow.com/a/9753006/6825678 – DrHopfen Jun 27 '18 at 07:31
  • why would you have classes under src/public/java ? Why do you even have a src/public/java ? – Stultuske Jun 27 '18 at 07:31
  • @DrHopfen, the solution worked, thanks for routing me to correct direction. – Dipan Jun 27 '18 at 07:44
  • 1
    Remove that supplemental directory and follow the conventions. Put your production code into `src/main/java` ....that will solve the problem...and don't start to use things like build-helper-maven-plugin.... – khmarbaise Jun 27 '18 at 17:59
  • @khmarbaise, will move all the code in src/main/java before moving to production. Wondering why not to use build-helper-maven-plugin. Is there something I should be aware of, do let me know. Thanks. – Dipan Sep 01 '18 at 18:01

0 Answers0