如何使用 deploy java heroku 修复语言级别

How to fix language-level with deploy java heroku

推送到 git 应用程序后部署应用程序然后发出日志

1.6以上支持的语言版本写错了但是一开始你可以看到1.7的语言版本

> -----> Java app detected
-----> Installing OpenJDK 1.7... done
-----> Installing Maven 3.1.1... done
-----> executing /app/tmp/cache/.maven/bin/mvn -B -Duser.home=/tmp/build_0f74c7a1296de88f7a8d95975dd06c6b -Dmaven.repo.local=/app/tmp/cache/.m2/repository  -DskipTests=true clean install
       [INFO] Scanning for projects...
       [INFO]                                                                         
       [INFO] ------------------------------------------------------------------------
       [INFO] Building cashconverter 1.0-SNAPSHOT
       [INFO] ------------------------------------------------------------------------
       [INFO] Downloading:ada linkhttp://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.5.1/maven-compiler-plugin-2.5.1.pom
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.5.1/maven-compiler-plugin-2.5.1.pom (8 KB at 31.2 KB/sec)
       [INFO] Downloading: linkhttp://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.5.1/maven-compiler-plugin-2.5.1.jar
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.5.1/maven-compiler-plugin-2.5.1.jar (32 KB at 1587.3 KB/sec)
       [INFO] 
       [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ cashconverter ---
       [INFO] 
       [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ cashconverter ---
       [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
       [INFO] skip non existing resourceDirectory /tmp/build_0f74c7a1296de88f7a8d95975dd06c6b/src/main/resources
       [INFO] 
       [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ cashconverter ---
       [INFO] Downloading: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/1.9.1/plexus-compiler-api-1.9.1.pom
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/1.9.1/plexus-compiler-api-1.9.1.pom (867 B at 77.0 KB/sec)
       [INFO] Downloading: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler/1.9.1/plexus-compiler-1.9.1.pom
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler/1.9.1/plexus-compiler-1.9.1.pom (4 KB at 220.6 KB/sec)
       [INFO] Downloading: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.20/plexus-components-1.1.20.pom
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.20/plexus-components-1.1.20.pom (3 KB at 267.8 KB/sec)
       [INFO] Downloading: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/1.9.1/plexus-compiler-manager-1.9.1.pom
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/1.9.1/plexus-compiler-manager-1.9.1.pom (692 B at 61.4 KB/sec)
       [INFO] Downloading: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/1.9.1/plexus-compiler-javac-1.9.1.pom
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/1.9.1/plexus-compiler-javac-1.9.1.pom (688 B at 67.2 KB/sec)
       [INFO] Downloading: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compilers/1.9.1/plexus-compilers-1.9.1.pom
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compilers/1.9.1/plexus-compilers-1.9.1.pom (2 KB at 121.4 KB/sec)
       [INFO] Downloading: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/1.9.1/plexus-compiler-api-1.9.1.jar
       [INFO] Downloading: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/1.9.1/plexus-compiler-manager-1.9.1.jar
       [INFO] Downloading: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/1.9.1/plexus-compiler-javac-1.9.1.jar
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/1.9.1/plexus-compiler-manager-1.9.1.jar (5 KB at 317.8 KB/sec)
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/1.9.1/plexus-compiler-api-1.9.1.jar (21 KB at 1305.8 KB/sec)
       [INFO] Downloaded: linkhttp://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/1.9.1/plexus-compiler-javac-1.9.1.jar (14 KB at 931.8 KB/sec)
       [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
       [INFO] Compiling 5 source files to /tmp/build_0f74c7a1296de88f7a8d95975dd06c6b/target/classes
       [INFO] -------------------------------------------------------------
       [ERROR] COMPILATION ERROR : 
       [INFO] -------------------------------------------------------------
       [ERROR] /tmp/build_0f74c7a1296de88f7a8d95975dd06c6b/src/main/java/servlet/ConventerServlet.java:[64,20] error: strings in switch are not supported in -source 1.5
       [ERROR]   (use -source 7 or higher to enable strings in switch)
       /tmp/build_0f74c7a1296de88f7a8d95975dd06c6b/src/main/java/servlet/ConventerServlet.java:[80,20] error: strings in switch are not supported in -source 1.5
       [INFO] 2 errors 
       [INFO] -------------------------------------------------------------
       [INFO] ------------------------------------------------------------------------
       [INFO] BUILD FAILURE
       [INFO] ------------------------------------------------------------------------
       [INFO] Total time: 3.135s
       [INFO] Finished at: Fri Jan 09 18:46:12 UTC 2015
       [INFO] Final Memory: 16M/514M
       [INFO] ------------------------------------------------------------------------
       [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project cashconverter: Compilation failure: Compilation failure:
       [ERROR] /tmp/build_0f74c7a1296de88f7a8d95975dd06c6b/src/main/java/servlet/ConventerServlet.java:[64,20] error: strings in switch are not supported in -source 1.5
       [ERROR] (use -source 7 or higher to enable strings in switch)
       [ERROR] /tmp/build_0f74c7a1296de88f7a8d95975dd06c6b/src/main/java/servlet/ConventerServlet.java:[80,20] error: strings in switch are not supported in -source 1.5
       [ERROR] -> [Help 1]
       [ERROR] 
       [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
       [ERROR] Re-run Maven using the -X switch to enable full debug logging.
       [ERROR] 
       [ERROR] For more information about the errors and possible solutions, please read the following articles:
       [ERROR] [Help 1] linkhttp://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
 !     ERROR: Failed to build app with Maven
 !     Push rejected, failed to compile Java app

pom.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.heroku.sample</groupId>
  <artifactId>cashconverter</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>cashconverter</name>
  <url>http://maven.apache.org</url>
  <properties>
    <tomcat.version>7.0.34</tomcat.version>
  </properties>
  <dependencies>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-logging-juli</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jasper</artifactId>
        <version>${tomcat.version}</version>
    </dependency>



      <dependency>
          <groupId>org.json</groupId>
          <artifactId>json</artifactId>
          <version>20090211</version>
      </dependency>

      <dependency>
          <groupId>com.google.code.gson</groupId>
          <artifactId>gson</artifactId>
          <version>2.2.4</version>
      </dependency>

    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jasper-el</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jsp-api</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>cashconverter</finalName>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <version>1.1.1</version>
            <configuration>
                <assembleDirectory>target</assembleDirectory>
                <programs>
                    <program>
                        <mainClass>launch.Main</mainClass>
                        <name>webapp</name>
                    </program>
                </programs>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>assemble</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>
</project>

请告诉我如何解决这个问题

您很可能需要告诉 Maven 专门使用您需要的 Java 版本。它使用默认值,即 from the Maven website(强调我的):

Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.

你应该特别告诉 Maven 编译器插件使用你想要的 Java 版本。这是一个也是 from the Maven website:

的例子
<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.2</version>
        <configuration>
          <source>1.4</source>
          <target>1.4</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

对我来说,maven-compiler-plugin 不是必需的,只有

<plugin>
    <groupId>com.heroku.sdk</groupId>
    <artifactId>heroku-maven-plugin</artifactId>
    <version>1.0.0</version>
</plugin>

在 pom.xml.
使用 heroku:deploy 命令部署应用程序,没问题(我的代码有 Java 8 个功能)。

当我尝试使用 git push 手动(为了好玩)推送到应用程序存储库时,出现了 -source 1.5 错误,我什至无法使用 heroku:deploy 进行部署没有了。

不得不使用 mkobit 的 解决方案。貌似只要在使用Maven和Heroku时不手动push,就可以使用heroku:deploy

此外,请确保项目 IDE 中的所有设置都对应于源 1.7 或您需要的任何设置。