Не удается найти указанный файл exec-maven-plugin
Maven не находит файл, который находится в папке resourses. Подскажите, как решить эту проблему, как и что поменять?
Ошибка:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java (default-cli) on project pathToCSVAndDateToInt: An exception occured while executing
the Java class. file.csv (Не удается найти указанный файл) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Код java:
package org.example;
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvValidationException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class main {
public static void main (String[] args) throws IOException, CsvValidationException {
CSVReader csvReader = new CSVReader(new FileReader("file.csv"));
String[] arrayString;
while((arrayString = csvReader.readNext()) != null) {
System.out.println(arrayString);
}
}
}
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>org.example</groupId>
<artifactId>pathToCSVAndDateToInt</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>org.example.main</mainClass>
<arguments>
<argument>-Dproperty=first</argument>
<argument>-Dproperty=second</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Сам файл лежит в папке ресурсы:
Ответы (1 шт):
Автор решения: Aziz Umarov
→ Ссылка
Попробуйте так
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is = classloader.getResourceAsStream("file.csv");
Если тяжело разобраться то можно получить файл.
URI uri = classloader.getResource("file.csv").getURI();
CSVReader csvReader = new CSVReader(new FileReader(new File(uri)));
