Rahul Raj
Rahul Raj

Reputation: 3439

Spring Boot application failure - Error java package does not exist

I'm having a Spring Boot project referring to an external module to execute the results.

enter image description here

I have already added the external module under module dependencies:

enter image description here

However when I run the Spring Boot application, it fails with this error: Error:(3, 16) java: package examples does not exist

enter image description here

CustomerLossPrediction in the below source referring to external module and call to this module fails even though I added the module to project workspace and dependencies are added correctly.

package com.example.demo.service;

import examples.CustomerLossPrediction;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Service
public class DL4JServiceImpl implements DL4JService {
    @Override
    public String fetchPrediction(MultipartFile file) throws IOException, InterruptedException {
        File convFile = new File( file.getOriginalFilename());
        file.transferTo(convFile);
        INDArray array = new CustomerLossPrediction().generateOutput(convFile);
        return array.toString();
    }
}

Here is the pom.xml if needed:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
<!--        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nd4j</groupId>
            <artifactId>nd4j-api</artifactId>
            <version>0.8.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <classifier>exec</classifier>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

I'm thinking it happens because I tried to refer an external module that is some way or the other cannot refer from Spring Boot module?

Upvotes: 1

Views: 4599

Answers (1)

Antoniossss
Antoniossss

Reputation: 32507

You have to add that external module as maven dependency. If you fail to do so, even if you manage to run it from IDE, it will fail to build with Maven.

Here you have explained how to install JAR as Maven artifact. When you do that, include it as dependency in POM

https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Upvotes: 3

Related Questions