1

As seen in the screenshot the module/project are set to jdk 1.7

Project / sdk set to 7:

enter image description here

Module set to jdk 7:

enter image description here

However from javap we are seeing java6 (50) ??

a) Confirm the class were just now compiled (7/22/15 @18:14) :

ls -l ./target/classes/org/yardstickframework/spark/DataGenerator.class
-rw-r--r--  1 steve  staff  3829 Jul 22 18:14 ./target/classes/org/yardstickframework/spark/DataGenerator.class

b) Which version of java?

javap -verbose ./target/classes/org/yardstickframework/spark/DataGenerator.class | grep ver
  minor version: 0
  major version: 50

Note: The pom.xml sets language level to jdk7

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

Update Per a suggestion I ran the compilation from command line :

mvn clean compile

This results also in jdk6 /major version=50. Now why would that be? I am examining the POM to see if other weirdness present.

Another update Per Roman's request: here is maven output

$mvn -v
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700)
Maven home: /usr/local/Cellar/maven/3.1.1/libexec
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10", arch: "x86_64", family: "mac"

Yet another update ElliottFrisch suggested some additions to the maven compiler plugin. Here is the updated section:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <fork>true</fork>
                <verbose>true</verbose>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
  • What is the value of your `JAVA_HOME` variable? – Tim Biegeleisen Jul 23 '15 at 01:30
  • I do not believe that matters, but in any case: $echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home – WestCoastProjects Jul 23 '15 at 01:32
  • What error are you getting when you run? Yes, `JAVA_HOME` should not matter. – Tim Biegeleisen Jul 23 '15 at 01:36
  • 1
    Is this a maven project? Maybe the source and target level are set to 1.6 in your POM? What happens when you build this from command line? Leave "Project bytecode version" setting blank for JDK default as well. – Strelok Jul 23 '15 at 01:39
  • @Strelok I was incorrect. The language level is 1.7 from maven. But at the same time - the compilation from command line maven is ALSO doing **jdk6**. Getting stranger here .. – WestCoastProjects Jul 23 '15 at 01:51
  • Maven uses javax.tools by default to do the compilation, can you try setting the target level to 1.7 in the POM and add `-Dmaven.compiler.forceJavacCompilerUse=true` to mvn command line? https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html – Strelok Jul 23 '15 at 01:54
  • Also check the java version maven is using: `mvn -v` – Roman Jul 23 '15 at 01:55
  • @Strelok I added your -D switch : "mvn -Dmaven.compiler.forceJavacCompilerUse=true clean compile" . It had no effect. – WestCoastProjects Jul 23 '15 at 01:59
  • @Roman I ran "mvn -v" and updated the OP. It shows jdk 7 – WestCoastProjects Jul 23 '15 at 01:59
  • Can you add `true` to your ``? I also have `true` (in ``), and `org.apache.maven.plugins` before ``. – Elliott Frisch Jul 23 '15 at 02:03
  • @ElliottFrisch OK trying your suggestions.. No effect. But seems strange - what kinds of messages would I expect given that verbose were set to true?? btw I updated the OP to show the mods to the maven compiler plugin section. – WestCoastProjects Jul 23 '15 at 02:13
  • A bit far fetched but seemed to be a case for another SO question. Can you check the actual mvn shell script to check if it's overriding JAVA_HOME somewhere inside it? – Strelok Jul 23 '15 at 03:12
  • @Strelok Apologies here - this is a mixed scala/java project and I did not consider that the scala plugin has a mind of its own. Please see the answer I provided. – WestCoastProjects Jul 23 '15 at 03:29

1 Answers1

2

OK I am a bit sheepish on this. This is a scala project and the class files are outputs from the scala-maven plugin. So all those maven-compiler settings only apply to java source files. Sorry about that huge missing factoid folks.

The means to get the proper version within the scala-maven-plugin is not straightforward to determine: but luckily someone has figured it out:

http://xflin.blogspot.com/2013/08/mixed-scala-and-java-in-maven-project.html

Here is the key piece:

    <recompileMode>incremental</recompileMode>
    <args>
      <arg>-target:jvm-1.7</arg>
    </args>
    <javacArgs>
      <javacArg>-source</javacArg><javacArg>1.7</javacArg>
      <javacArg>-target</javacArg><javacArg>1.7</javacArg>
    </javacArgs>

That goes within the normal scala-maven-plugin section which looks like:

        <plugin>
            <version>3.2.1</version>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <scalaCompatVersion>${scala.version}</scalaCompatVersion>
                <scalaVersion>${scala.binary.version}</scalaVersion>
                <jvmArgs>
                    <jvmArg>-Xms512m</jvmArg>
                    <jvmArg>-Xmx1024m</jvmArg>
                </jvmArgs>
              <recompileMode>incremental</recompileMode>
              <args>
                <arg>-target:jvm-1.7</arg>
              </args>
              <javacArgs>
                <javacArg>-source</javacArg><javacArg>1.7</javacArg>
                <javacArg>-target</javacArg><javacArg>1.7</javacArg>
              </javacArgs>
          </configuration>
        </plugin>

After adding that piece to the scala plugin we now have:

$javap -verbose ./target/classes/org/yardstickframework/spark/DataGenerator.class | grep ver
  minor version: 0
  major version: 51
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560