Compilation error when using Streams and Maven

I got a weird compilation error when trying to compile my code with Maven , my code is running inside Eclipse, I am using Java 8 and Files.lines

for read the file.

[INFO] Compiling 8 source files to /Users/nilemarbarcelos/Dev/ConferenceTrackManager/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/nilemarbarcelos/Dev/ConferenceTrackManager/src/main/java/com/nilemarbarcelos/FileInputHandler.java:[29,69] incompatible types: java.util.List<java.lang.Object> cannot be converted to java.util.List<java.lang.String>
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.122 s
[INFO] Finished at: 2015-05-03T14:26:41-03:00
[INFO] Final Memory: 14M/211M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project ConferenceTrackManager: Compilation failure
[ERROR] /Users/nilemarbarcelos/Dev/ConferenceTrackManager/src/main/java/com/nilemarbarcelos/FileInputHandler.java:[29,69] incompatible types: java.util.List<java.lang.Object> cannot be converted to java.util.List<java.lang.String>
[ERROR] -> [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/MojoFailureException

      

The code looks like this:

List<String> lines = null;
        try {
            URL path = getClass().getClassLoader().getResource(source);
            if (Objects.isNull(path)) {
                throw new FileNotFoundException("File not found");
            }
            lines = Files.lines(Paths.get(path.toURI())).collect(Collectors.toList());

      

Where I am using the method collect()

.

Can anyone help me solve this error?

+3


source to share


2 answers


You don't have a POM here, but you probably didn't specify the JDK :

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>

      



Once you've added this to <plugins>

your POM section and executed mvn clean install

, the error should resolve on its own.

+3


source


It looks like your pom file is missing maven-compiler-plugin

.



By default, Maven compile

does not use the 1.8 JDK version for.

+2


source







All Articles