简单的编译在Maven下失败,在Javac下成功 [英] Simple compilation fails under Maven, succeeds with javac

查看:104
本文介绍了简单的编译在Maven下失败,在Javac下成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Maven项目,其中包含一个文件App.java,其中包含

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;
        }
    }
}

(您可以通过在5分钟的项目创建中使用Maven并将其替换为上面的App.java来复制它.)

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

mvn compile产生

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

导航到目录并运行javac App.java时,

不会产生任何错误.有人知道怎么回事吗? (我假设Maven使用了我的盒子上安装的Java版本;无论如何,都是1.6.0_21.谢谢.

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.

推荐答案

它可能是使用sourcetarget版本1.4进行编译的.您将需要配置编译器插件以进行更高版本的编译.请参见如何设置Maven,使其可以与目标和源JVM一起编译.我的选择?" :

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>
  ...

这篇关于简单的编译在Maven下失败,在Javac下成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆