如何使用 Heroku & Maven 和 GitHub 托管我的电报机器人 [JAVA]?
How To Host My Telegram Bot [JAVA] Using Heroku & Maven and GitHub?
我的 pom.xml 文件:
<modelVersion>4.0.0</modelVersion>
<groupId>TelegramBOT</groupId>
<artifactId>TelegramBOT</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<release>13</release>
<appName>TelegramBOT</appName>
<processTypes>
<web>java $JAVA_OPTS -cp target/classes:target/dependency/* Main</web>
</processTypes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.telegram/telegrambots -->
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9</version>
</dependency>
</dependencies>
</project>
这是 pom.xml 的版本,但我无法在 Heroku 中托管...它显示错误
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.182 s
[INFO] Finished at: 2020-06-28T11:59:51Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project TelegramBOT: Compilation failure: Compilation failure:
[ERROR] /tmp/build_07ca4d72478d669dcc1d1150921b9882/src/com/TelegramBot/EraserHead/GameHandler.java:[17,60] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /tmp/build_07ca4d72478d669dcc1d1150921b9882/src/com/TelegramBot/EraserHead/ImageGuess.java:[23,60] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[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] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
! ERROR: Failed to build app with Maven
We're sorry this build is failing! If you can't find the issue in application code,
please submit a ticket so we can help: https://help.heroku.com/
! Push rejected, failed to compile Java app.
! Push failed
这是 Heroku 控制台 ....
但是在 Eclipse 控制台中显示构建成功!
我不知道该怎么办……我真的需要创建 Procfile 吗???
请帮助...如果您需要查看我的程序的源代码,
它在我的 GitHub 帐户中:https://github.com/saikat0326/Saikat-Telegram-BOT
提前致谢...
看起来 Maven Compiler 插件正在使用 Java 5(默认情况下应该使用 Java 6),因此您会收到构建错误 diamond operator is not supported in -source 1.5
Heroku 支持各种 Java 版本(参见 Supported Java versions),您应该能够在 POM 文件中设置目标版本
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
菱形运算符 – 在 Java 1.7 中引入 – 添加类型推断并减少赋值中的冗长。
你的源代码中的问题尝试re-write它。
我有类似的问题,我现在看起来像这样
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<webjars-bootstrap.version>4.1.3</webjars-bootstrap.version>
<webjars-jquery-ui.version>1.12.1</webjars-jquery-ui.version>
<webjars-jquery.version>3.3.1-1</webjars-jquery.version>
<java.version>${java.version}</java.version>
<maven.compiler.source>${versions-maven-plugin.version}</maven.compiler.source>
<maven.compiler.target>${versions-maven-plugin.version}</maven.compiler.target>
</properties>
我的 pom.xml 文件:
<modelVersion>4.0.0</modelVersion> <groupId>TelegramBOT</groupId> <artifactId>TelegramBOT</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <groupId>com.heroku.sdk</groupId> <artifactId>heroku-maven-plugin</artifactId> <version>3.0.2</version> <configuration> <release>13</release> <appName>TelegramBOT</appName> <processTypes> <web>java $JAVA_OPTS -cp target/classes:target/dependency/* Main</web> </processTypes> </configuration> </plugin> </plugins> </build> <dependencies> <!-- https://mvnrepository.com/artifact/org.telegram/telegrambots --> <dependency> <groupId>org.telegram</groupId> <artifactId>telegrambots</artifactId> <version>4.9</version> </dependency> </dependencies> </project>
这是 pom.xml 的版本,但我无法在 Heroku 中托管...它显示错误
[INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 10.182 s [INFO] Finished at: 2020-06-28T11:59:51Z [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project TelegramBOT: Compilation failure: Compilation failure: [ERROR] /tmp/build_07ca4d72478d669dcc1d1150921b9882/src/com/TelegramBot/EraserHead/GameHandler.java:[17,60] diamond operator is not supported in -source 1.5 [ERROR] (use -source 7 or higher to enable diamond operator) [ERROR] /tmp/build_07ca4d72478d669dcc1d1150921b9882/src/com/TelegramBot/EraserHead/ImageGuess.java:[23,60] diamond operator is not supported in -source 1.5 [ERROR] (use -source 7 or higher to enable diamond operator) [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] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException ! ERROR: Failed to build app with Maven We're sorry this build is failing! If you can't find the issue in application code, please submit a ticket so we can help: https://help.heroku.com/ ! Push rejected, failed to compile Java app. ! Push failed
这是 Heroku 控制台 ....
但是在 Eclipse 控制台中显示构建成功! 我不知道该怎么办……我真的需要创建 Procfile 吗??? 请帮助...如果您需要查看我的程序的源代码, 它在我的 GitHub 帐户中:https://github.com/saikat0326/Saikat-Telegram-BOT 提前致谢...
看起来 Maven Compiler 插件正在使用 Java 5(默认情况下应该使用 Java 6),因此您会收到构建错误 diamond operator is not supported in -source 1.5
Heroku 支持各种 Java 版本(参见 Supported Java versions),您应该能够在 POM 文件中设置目标版本
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
菱形运算符 – 在 Java 1.7 中引入 – 添加类型推断并减少赋值中的冗长。
你的源代码中的问题尝试re-write它。
我有类似的问题,我现在看起来像这样
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<webjars-bootstrap.version>4.1.3</webjars-bootstrap.version>
<webjars-jquery-ui.version>1.12.1</webjars-jquery-ui.version>
<webjars-jquery.version>3.3.1-1</webjars-jquery.version>
<java.version>${java.version}</java.version>
<maven.compiler.source>${versions-maven-plugin.version}</maven.compiler.source>
<maven.compiler.target>${versions-maven-plugin.version}</maven.compiler.target>
</properties>