Skip to content

Document how to provide runtime JVM arguments when building an image #21478

@sergey-morenets

Description

@sergey-morenets

Hi

I'm using Spring Boot 2.3.0 and JDK 14.0.1 and want to pack my application using new buildpack feature in Spring Boot Maven plugin.
Since I use preview features I have to add "--enable-preview" flag as JVM argument (JAVA_OPTS environment variable).

So here's my Spring Boot Maven plugin configuration:

			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<jvmArguments>
						--enable-preview
					</jvmArguments>
					<image>
						<env>
							<JAVA_OPTS>--enable-preview</JAVA_OPTS>
						</env>
					</image>
				</configuration>
				<executions>
					<execution>
						<id>buildImage</id>
						<goals>
							<goal>build-image</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

Docker image is built successfully but container fails to start with exception:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Preview features are not enabled for demo/Application (class file version 58.65535). Try running with '--enable-preview'

And resulting JAVA_OPTS environment variable in the image is missing my argument:
-Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -agentpath:/layers/paketo-buildpacks_bellsoft-liberica/jvmkill/jvmkill-1.16.0-RELEASE.so=printHeapHistogram=1 -XX:ActiveProcessorCount=2 -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=104953K -XX:ReservedCodeCacheSize=240M -Xss1M -Xmx431622K -Dio.paketo.openssl.ca-certificates=/etc/ssl/certs/ca-certificates.crt

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions