简体   繁体   English

Spring Boot 应用程序失败 - 错误 java 包不存在

[英]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.我有一个引用外部模块的 Spring Boot 项目来执行结果。

在此处输入图片说明

I have already added the external module under module dependencies:我已经在模块依赖项下添加了外部模块:

在此处输入图片说明

However when I run the Spring Boot application, it fails with this error: Error:(3, 16) java: package examples does not exist但是,当我运行 Spring Boot 应用程序时,它失败并显示以下错误: Error:(3, 16) java: package examples does not exist

在此处输入图片说明

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.以下源代码中的CustomerLossPrediction引用外部模块并调用此模块失败,即使我将模块添加到项目工作区并且正确添加了依赖项。

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:如果需要,这里是pom.xml

<?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?我认为这是因为我试图引用某个外部模块,或者另一个模块无法从 Spring Boot 模块引用?

You have to add that external module as maven dependency.您必须将该外部模块添加为 maven 依赖项。 If you fail to do so, even if you manage to run it from IDE, it will fail to build with Maven.如果你不这样做,即使你设法从 IDE 运行它,它也将无法使用 Maven 构建。

Here you have explained how to install JAR as Maven artifact.在这里,您已经解释了如何将 JAR 安装为 Maven 工件。 When you do that, include it as dependency in POM当您这样做时,将其作为依赖项包含在 POM 中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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