Maven 编译错误。执行 javac 失败,但无法解析错误:javac: invalid flag: -s

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20733171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:53:45  来源:igfitidea点击:

Maven compilation error. Failure executing javac, but could not parse the error:javac: invalid flag: -s

javamaven

提问by Sajith

I am getting a compilation error when try to execute mvn clean install.

尝试执行 mvn clean install 时出现编译错误。

 [ERROR] COMPILATION ERROR :
    [INFO] -------------------------------------------------------------
    [ERROR] Failure executing javac, but could not parse the error:
    javac: invalid flag: -s
    Usage: javac <options> <source files>

Java version is

Java版本是

java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode, sharing)

Maven version

Maven版本

Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600)
Maven home: C:\Sajith\apache-maven-3.0.3\apache-maven-3.0.3
Java version: 1.5.0_16, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.5.0_16\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"

Pom.xml

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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test.sample</groupId>
    <artifactId>TestApp</artifactId>
    <description>TestApp Release 1.0 Build</description>
    <version>2.0</version>
    <packaging>pom</packaging>
    <name>TestApp API</name>
    <url>http://maven.apache.org</url>

Any help would be appreciated.

任何帮助,将不胜感激。

采纳答案by Viktor K.

The problem is that your maven is using java 5 (as your comment says). You have to change your JAVA_HOME variable to point to jdk 6 or higher. Look at :

问题是您的 Maven 正在使用 java 5(正如您的评论所说)。您必须将 JAVA_HOME 变量更改为指向 jdk 6 或更高版本。看着 :

Error when using javac: "javac: invalid flag: -s"

使用 javac 时出错:“javac:无效标志:-s”

回答by Pichitron

In my case i dont have the apropiate environment variable because the project is inherited, and I had not created the variable JDK_WAS85_JDK8 = C:\Program Files\Java\jdk1.8.0_221. Usually is JAVA_HOME the variable that is set. father pom.xml

在我的情况下,我没有 apropiate 环境变量,因为项目是继承的,而且我没有创建变量 JDK_WAS85_JDK8 = C:\Program Files\Java\jdk1.8.0_221。通常是JAVA_HOME设置的变量。 父亲pom.xml