Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在pom中设置Maven源没有效果_Java_Maven - Fatal编程技术网

Java 在pom中设置Maven源没有效果

Java 在pom中设置Maven源没有效果,java,maven,Java,Maven,恐怕我已经用谷歌搜索出了这个问题,所有的答案都说只需在pom中输入以下内容: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version>

恐怕我已经用谷歌搜索出了这个问题,所有的答案都说只需在pom中输入以下内容:

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
      <source>1.5</source>
      <target>1.5</target>
    </configuration>
  </plugin>
  ...
</plugins>
...
而且

java -version
给予

显示

Java version: 1.8.0, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre
此外,当我启用调试信息时,它显示它正在使用1.5源代码,无论我在pom中输入了什么:

[DEBUG]   (f) showDeprecation = false
[DEBUG]   (f) showWarnings = false
[DEBUG]   (f) skipMultiThreadWarning = false
[DEBUG]   **(f) source = 1.5**
[DEBUG]   (f) staleMillis = 0
[DEBUG]   **(f) target = 1.5**
[DEBUG]   (f) useIncrementalCompilation = true
[DEBUG]   (f) verbose = false
[DEBUG]   (f) mavenSession = org.apache.maven.execution.MavenSession@4648ce9
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@4648ce9
[DEBUG] -- end configuration --
我最后的猜测是,这是因为我只使用了一个未打包的mvn脚本,而我并没有实际安装它(我必须在运行它时指定它的完整路径),我觉得这太傻了


此外,我在IntelliJ中使用maven,虽然我不能从命令行调用该maven,但可能它们的存储库/配置相互干扰?

我建议您包括
编译器版本
参数:

            <configuration>
                <compilerVersion>1.8</compilerVersion>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>

1.8
1.8
1.8

我使用以下属性:

  <properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

1.8
UTF-8
1.8
1.8
配置编译器插件。
至少在Eclipse中,这很好。

编译错误是由Maven本身还是IntelliJ给出的?我不知道IntelliJ,但在Eclipse中,每当pom中的Java版本发生变化时,项目都需要更新,以便Eclipse能够理解这一变化,从而可以使用正确的Java版本进行编译。不,我在尝试通过命令行编译时,在没有任何IDE的情况下,会遇到这些错误。您编写“我不能从命令行给那个maven打电话。”现在你突然可以了?@GeroldBroser:不完全是,我说“我不能从命令行给那个maven打电话。”“,这是IntelliJ使用的maven,但我可以调用我下载的版本。啊,我使用了最后两个版本,但添加java版本显然有所帮助。非常感谢。虽然它在目前有帮助,但我不希望用静态值覆盖。一旦安装的Java版本更改,这可能会导致不良影响。我认为真正的罪魁祸首是别的东西。“我使用的只是一个未打包的mvn脚本,实际上我并没有安装它”,例如。@GeroldBroser,谢谢,我会记住这是一个糟糕的做法。我很高兴它最终能在我的测试机器上运行,并且在目标机器上已经安装了maven,所以希望它能在那里运行,而不需要我重写系统配置。。。如果
fork
设置为
true
。。。叉默认值为:
false
@Gerold Broser Aha。这是正确的。好的,另一种尝试(虽然不是真正针对这个奇怪问题的实际原因)是设置
fork=true
以及
compilervision=1.8
[DEBUG]   (f) showDeprecation = false
[DEBUG]   (f) showWarnings = false
[DEBUG]   (f) skipMultiThreadWarning = false
[DEBUG]   **(f) source = 1.5**
[DEBUG]   (f) staleMillis = 0
[DEBUG]   **(f) target = 1.5**
[DEBUG]   (f) useIncrementalCompilation = true
[DEBUG]   (f) verbose = false
[DEBUG]   (f) mavenSession = org.apache.maven.execution.MavenSession@4648ce9
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@4648ce9
[DEBUG] -- end configuration --
            <configuration>
                <compilerVersion>1.8</compilerVersion>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
  <properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>