question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.classpath keeps changing to Java 1.8, not what is in pom.xml (11)

See original GitHub issue

I have a project that was generated by JHipster that has always used Java 11, which is specified in the POM.

        <java.version>11</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>

However, every time .classpath is generated it specifies Java 1.8:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">

Then I have manually change it to java 11:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">

This is similar to this issue .classpath file is not updated with new JDK version #1748 where they said to manually trigger a configuration update with the “Update Configuration” command. I have done that and it also changes it to Java 1.8 😕

Environment
  • Operating System: Windows 10 Enterprise 10.0.19044 Build 19044
  • JDK version: 11
  • Visual Studio Code version: 1.68.0
  • Java extension version: v0.23.0 (Last updated 6/12/2022, 20:07:00)
Steps To Reproduce
  1. manually trigger a configuration update with the “Update Configuration”
  2. Java version changes to 1.8, NOT the version in pom.xml

[Please attach a sample project reproducing the error] Please attach logs

Current Result

.classpath is configured for Java 1.8, not the version specified in pom.xml

Expected Result

.classpath should match the pom.xml file, which is configured for Java 11

Additional Informations

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kkalasscommented, Jun 22, 2022

I had a very similar issue with JavaSE-11 being changed to JavaSE-12 automatically by vscode in my maven java projects. In my case it was caused by maven-enforcer-plugin. When I changed the version underneath plugin/executions/execution/configuration/rules/requireJavaVersion in

	<plugin>
		<artifactId>maven-enforcer-plugin</artifactId>
		<version>3.1.0</version>
		<executions>
			<execution>
				<id>enforce-java</id>
				<goals>
					<goal>enforce</goal>
				</goals>
				<phase>validate</phase>
				<configuration>
					<rules>
						<requireJavaVersion>
							<version>11.0.4</version>
						</requireJavaVersion>
					</rules>
				</configuration>
			</execution>
		</executions>
	</plugin>

from <version>11.0.4</version> to <version>[11.0,12.0)</version>, then it stopped changing the java version.

Maybe it is also some maven plugin in your case causing this?

0reactions
karlvrcommented, Jul 5, 2022

@kkalass thanks for the tip, this is what my maven-enforcer-plugin was set to:

<requireJavaVersion>
	<version>[1.8.0,)</version>
</requireJavaVersion>

It doesn’t feel like I got the right result, as 1.8.0 is just the minimum and it chose 1.8 even though I have both 11 and 17, but changing that to 17 has fixed the issue with VS Code choosing 1.8 for my project in spite of the compiler plugin stipulating 17. Much thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java version automatically change to java 1.5 after maven ...
I changed "Java build path" to "workspace default jre 1.8.0_25" · Then changed "java compiler" to 1.8 · Then changed "project facets">java>1.8 ·...
Read more >
How to force JDK 1.8 compliance in a Maven POM example
The only way to make this a permanent change is to edit the Maven compiler plugin POM entry and force Eclipse and Maven...
Read more >
Transition from Java 8 to Java 11 - Azure - Microsoft Learn
In this article. The toolbox; Running on Java 11; Next steps. There's no one-size-fits-all solution to transition code from Java 8 to Java...
Read more >
Setting the -source and -target of the Java Compiler
To avoid this issue, you can either configure the compiler's boot classpath to match the target JRE, or use the Animal Sniffer Maven...
Read more >
Building Java & JVM projects - Gradle User Manual
compileOnly — for dependencies that are necessary to compile your production code but shouldn't be part of the runtime classpath. implementation (supersedes ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found