0

I'm having problems getting maven to compile with the correct version of java. I've installed maven and I'm trying to compile java code with java 1.8. However, maven only uses java 1.3. When I try to compile a project, here is the error I get:

$ mvn install

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hatman-dal 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ hatman-dal ---
[WARNING] Using platform encoding (ANSI_X3.4-1968 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/tyler/git/hatman-dal/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ hatman-dal ---
[INFO] Compiling 4 source files to /home/tyler/git/hatman-dal/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.727s
[INFO] Finished at: Thu Oct 27 21:22:49 PDT 2016
[INFO] Final Memory: 10M/89M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project hatman-dal: Compilation failure: Compilation failure:
[ERROR] /home/tyler/git/hatman-dal/src/main/java/com/hatman/dal/dao/TextPairRepository.java:[12,21] error: generics are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable generics)
[ERROR] /home/tyler/git/hatman-dal/src/main/java/com/hatman/dal/dao/util/FileStorage.java:[17,24] error: generics are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable generics)
[ERROR] /home/tyler/git/hatman-dal/src/main/java/com/hatman/dal/dao/impl/TextPairRepositoryFileStorageImpl.java:[17,15] error: generics are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable generics)
[ERROR] /home/tyler/git/hatman-dal/src/main/java/com/hatman/dal/dao/impl/TextPairRepositoryFileStorageImpl.java:[54,21] error: enhanced for loops are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable for-each loops)
[ERROR] /home/tyler/git/hatman-dal/src/main/java/com/hatman/dal/entity/TextPair.java:[27,5] error: annotations are not supported in -source 1.3
[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

More information for java and maven below:

pom.xml for the project:

$ cat pom.xml

<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.hatman</groupId>
    <artifactId>hatman-dal</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>
    <name>hatman-dal</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Effective pom:

$ mvn help:effective-pom

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hatman-dal 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-help-plugin:2.2:effective-pom (default-cli) @ hatman-dal ---
[INFO] 
Effective POMs, after inheritance, interpolation, and profiles are applied:

<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Generated by Maven Help Plugin on 2016-10-28T05:53:57                  -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/                -->
<!--                                                                        -->
<!-- ====================================================================== -->

<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Effective POM for project 'com.hatman:hatman-dal:jar:0.0.1'            -->
<!--                                                                        -->
<!-- ====================================================================== -->

<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.hatman</groupId>
  <artifactId>hatman-dal</artifactId>
  <version>0.0.1</version>
  <name>hatman-dal</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.4</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.8</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <sourceDirectory>/home/tyler/git/hatman-dal/src/main/java</sourceDirectory>
    <scriptSourceDirectory>/home/tyler/git/hatman-dal/src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>/home/tyler/git/hatman-dal/src/test/java</testSourceDirectory>
    <outputDirectory>/home/tyler/git/hatman-dal/target/classes</outputDirectory>
    <testOutputDirectory>/home/tyler/git/hatman-dal/target/test-classes</testOutputDirectory>
    <resources>
      <resource>
        <directory>/home/tyler/git/hatman-dal/src/main/resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>/home/tyler/git/hatman-dal/src/test/resources</directory>
      </testResource>
    </testResources>
    <directory>/home/tyler/git/hatman-dal/target</directory>
    <finalName>hatman-dal-0.0.1</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <id>default-clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <id>default-testResources</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
          <execution>
            <id>default-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <id>default-jar</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <executions>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.10</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <id>default-install</id>
            <phase>install</phase>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>default-deploy</id>
            <phase>deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0</version>
        <executions>
          <execution>
            <id>default-site</id>
            <phase>site</phase>
            <goals>
              <goal>site</goal>
            </goals>
            <configuration>
              <outputDirectory>/home/tyler/git/hatman-dal/target/site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
          <execution>
            <id>default-deploy</id>
            <phase>site-deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <outputDirectory>/home/tyler/git/hatman-dal/target/site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <outputDirectory>/home/tyler/git/hatman-dal/target/site</outputDirectory>
          <reportPlugins>
            <reportPlugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-project-info-reports-plugin</artifactId>
            </reportPlugin>
          </reportPlugins>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <outputDirectory>/home/tyler/git/hatman-dal/target/site</outputDirectory>
  </reporting>
</project>

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.888s
[INFO] Finished at: Fri Oct 28 17:53:58 PDT 2016
[INFO] Final Memory: 13M/89M
[INFO] ------------------------------------------------------------------------

Java version:

$ java -version

java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

Javac version:

$ javac -version

javac 1.8.0_111

Maven information:

$ mvn -version

Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.8.0_111, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.8.11", arch: "amd64", family: "unix"

Contents of ~/.mavenrc

$ cat ~/.mavenrc

export JAVA_HOME=/usr/lib/jvm/java-8-oracle

PATH:

$ echo $PATH

/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin

JAVA_HOME:

$ echo $JAVA_HOME

/usr/lib/jvm/java-8-oracle

I've seen similar questions, but so far I haven't been able to find a solution to my problem. I think I could set the source and target version in my pom.xml for each project (or set up a parent pom and do it there) but I'd really prefer to just have maven use the version specified from JAVA_HOME. I'm running Ubuntu through crouton on a Chromebook (if this makes any difference?). Any ideas?

endorphins
  • 586
  • 1
  • 4
  • 21
  • 1
    You showed us everything except the relevant part, i.e. the `pom.xml` file where the source version is likely specified. See https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html – Andreas Oct 28 '16 at 04:43
  • 1
    Or see this exact issue on SO (with solution): http://stackoverflow.com/a/15746354/3777824 – LinuxDisciple Oct 28 '16 at 04:44
  • @Andreas I've added the pom.xml, the source version is not included there. – endorphins Oct 28 '16 at 04:48
  • @LinuxDisciple I specifically said I preferred not to do that method so that I didn't have to do it for every project I want to compile. If that's the only way to fix it, then I can do it though... But I've never had this problem on other machines so it seems weird that it's happening now. – endorphins Oct 28 '16 at 04:49
  • I'm not suggesting that you add it, I'm suggesting that it's probably present and you should look for it elsewhere. Maven isn't choosing the wrong version by magic. Maven reads settings from all over. I'd do a `find /home/tyler/git/hatman-dal/ -type f |xargs grep -l "\<1.3\>"` and see what comes back. I bet you find some other .pom file or similar where the code I reference is specified. Also look in the Maven repo dir (for version 2 it was ~/.m2, so maybe ~/.m3 for you?). – LinuxDisciple Oct 28 '16 at 04:56
  • @LinuxDisciple the above command returned no results. As for the maven repo, it looks like it's still ~/.m2 (since I don't have an ~/.m3 directory). What specifically should I be looking for in ~/.m2/repository? – endorphins Oct 28 '16 at 05:04
  • To see if maven is merging in global configurations, try `mvn help:effective-pom`. It won't show *where* the values are coming from, but at least it'll help you see what maven sees. – Andreas Oct 28 '16 at 15:54
  • @Andreas I've included the effective pom as well using the above command. Looking at the compiler plugin, I don't see a source/target version specified. It doesn't look like it's being specified in there? I might be missing it though. – endorphins Oct 29 '16 at 01:01
  • You still didn't configure the plugin to _use_ the version of the JDK your code is. See https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html – Tunaki Oct 29 '16 at 21:47
  • @Tunaki is there a way I can do this for maven as a whole, as opposed to each individual project I want to compile? As I pointed out, I really don't want to have to do that for every project as it seems like it shouldn't be necessary. Worst case I'll make a parent pom and do it there, but it seems like I should be able to set the default for maven in general. I've also never had this problem before on a new machine, which is why I posted the question. – endorphins Oct 30 '16 at 04:34
  • @endorphins Putting it in a parent POM is indeed the good way to do that. – Tunaki Oct 30 '16 at 09:24

0 Answers0