将 Java 应用程序从 Eclipse 提交和推送到 Openshift 服务器时出错(不支持开关中的字符串)

Error while committing and pushing Java application from Eclipse to Openshift server (String in switch not supported)

构建失败

嗨,

我成功设置了所有内容以将更改应用于我位于 Openshift 服务器上的应用程序。突然间,我决定使用其他项目中的一些 Java 类,当我尝试提交更改时,出现此错误。

我对这个错误感到绝望,因为我研究了大约一天,google 对这个问题和相关问题一无所知。问题是我无法弄清楚“-source 7”代表什么,以及它是否与错误消息中上面一行中提到的“-source 1.6”有关。

错误信息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-   plugin:2.3.2:compile (default-compile) on project organizer: Compilation failure: Compilation failure:
[ERROR] /var/lib/openshift/56c42c687628e1f0a2000073/app-root/runtime/repo/src/main/java/organizer/DataOperations.java:[185,9] error: strings in switch are not supported in -source 1.6
[ERROR] (use -source 7 or higher to enable strings in switch)

在 switch 语句中使用 String 的每个实例都会重复此错误。

编辑:我正在寻找解决方案,而不仅仅是解释。正在尝试配置 pom 文件 atm。

非常感谢任何帮助..

谢谢,

Ondrej

如上所述,仅 Java 7+ 支持 Switch 语句中的字符串。

查看错误消息,您应该更新 POM 以包含以下内容,即针对 Java 7.

显式编译
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>7</source>
                    <target>7</target>
                </configuration>
            </plugin>
        </plugins?
    </pluginManagement>
<build>