rogerl
rogerl

Reputation: 207

Simple compilation fails under Maven, succeeds with javac

I have a simple Maven project that includes one file, App.java, containing

package com.foo;

public class App 
{
    private Long wrapper;

    public long getlong() {
        if (null != wrapper) {
            return wrapper;
        } else {
            return 0;
        }
    }
}

(You can duplicate this by using the Maven in 5 minutes project creation and replacing App.java with the above).

mvn compile produces

.../foo/App.java:[9,12] incompatible types
found   : java.lang.Long
required: long

while navigating to the directory and running javac App.java produces no errors. Anybody know what's up? (I assume that Maven uses whatever version of Java is installed on my box; in any case, that's 1.6.0_21. Thanks.

Upvotes: 1

Views: 962

Answers (1)

Mark Rotteveel
Mark Rotteveel

Reputation: 109088

It is probably compiling with a source or target version of 1.4. You will need to configure the compiler plugin to compile for a higher version. See "How do I set up Maven so it will compile with a target and source JVM of my choice?" and "Setting the -source and -target of the Java Compiler":

  ...
  <build>
  ...
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  ...
  </build>
  ...

Upvotes: 3

Related Questions