Heroku部署Java 13应用遇UnsupportedClassVersionError问题求助
Let's break down what's going wrong here and fix it step by step:
1. Fix your system.properties file
Your current system.properties has an invalid configuration for java.runtime.version — this property should only specify the Java version number, not include runtime flags or your main class. Update it to:
java.runtime.version=13
The --enable-preview flag can't be set here; we need to add it to the JVM arguments used to start your app instead.
2. Add --enable-preview to your appassembler-maven-plugin configuration
You're using the appassembler-maven-plugin to generate your startup script, but right now it's not including the preview features flag in the JVM arguments. Modify the <program> section of the plugin to add <jvmArguments>:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>appassembler-maven-plugin</artifactId> <version>2.1.0</version> <configuration> <assembleDirectory>target</assembleDirectory> <programs> <program> <mainClass>Main</mainClass> <name>teemitze-anna-bot</name> <!-- Add this line to enable preview features at runtime --> <jvmArguments>--enable-preview</jvmArguments> </program> </programs> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>assemble</goal> </goals> </execution> </executions> </plugin>
This ensures the generated startup script passes the --enable-preview flag to the JVM when launching your app.
3. Confirm your Maven compiler plugin setup is correct
Your existing maven-compiler-plugin configuration is already correct — it includes <compilerArgs>--enable-preview</compilerArgs> which enables preview features during compilation. This matches your class file version (57.65535, which is Java 13 with preview features), so no changes needed here.
4. Re-deploy your app
After making these changes:
- Run
mvn clean packagelocally to generate the updated startup script - Push your code to Heroku or re-deploy the updated package
Your app should now start successfully with preview features enabled.
内容的提问来源于stack exchange,提问作者Teemitze

