我有一个 Spring Boot 项目引用外部模块来执行结果。
我已经在模块依赖项下添加了外部模块:
但是,当我运行 Spring Boot 应用程序时,它失败并出现以下错误:
错误:(3, 16) java: 包示例不存在
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();
}
}
如果需要的话,这是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>
我认为发生这种情况是因为我试图以某种方式引用外部模块,或者其他模块无法从 Spring Boot 模块引用?
最佳答案
您必须将该外部模块添加为 Maven 依赖项。如果你不这样做,即使你设法从 IDE 运行它,它也将无法使用 Maven 构建。
这里您已经解释了如何将 JAR 安装为 Maven Artifact 。当您这样做时,将其作为依赖项包含在 POM 中
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
关于java - Spring Boot应用程序失败-错误java包不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51491127/