我有一个Spring Boot项目,它引用一个外部模块来执行结果。
但是,当我运行spring boot应用程序时,它失败并显示以下错误:
Error:(3, 16) java: package examples does not exist
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模块引用?高度赞赏是否有人能澄清这个谜题:)
答案 0 :(得分:2)
您必须将该外部模块添加为maven依赖项。如果这样做失败,即使您设法从IDE运行它,也将无法使用Maven进行构建。
在这里,您已经说明了如何将JAR安装为Maven工件。当您这样做时,请将其作为依赖项包含在POM中
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html