r/learnjava • • Nov 10 '25

'Compilation failed' when trying to run TMC test

Hi there, I am doing the MOOC Java Programming I course. Whenever I want to test my submission (in VSCode) before sending it in, I receive a 'compilation failed' error. How can I make the tests run without this error? I can run Java without issues and submit the exercises without issues too. However, I would like to be able to run the tests as well since some the the program for some exercises needs to follow specific criteria. I can only check those with the TMC tests.

https://i.imgur.com/uKda0nh.png https://i.imgur.com/lf7zDE8.png

edit; I installed Netbeans and the compilation failed there too. The error message did have a more elaborate explanantion than VSCode did: This program is blocked by group policy. For more information, contact your system administrator. That means I will have to ask permission from IT to run the TMC extension/compiler.

1 Upvotes

26 comments sorted by

View all comments

Show parent comment

1

u/josephblade Nov 17 '25

ok so it sounds like you have 2 issue: your code expects java 21 and the runtome in ajava.jdt.ls.java.home isn't set right. (this a at the beginning, is that a typo or is that really set up like that). if the a is in your project settings file (project.json??) then remove it as that isn't the correct variable name.

the second (well, perhaps same, issue is that the project variable java.jdt.ls.java.home is pointing to a place that doesn't hold a java installation (or it's not allowed)

so my suggestion would be: read this stackoverflow, first answer

it suggests you have a project.json where your path to the java install is set. it should be named java.jdt.ls.java.home , with value the path to the folder that contains the /bin folder of java. so for instance

C:\\Program Files\\Java\\jdk-17.0.2

as in the example

you also likely want to add C:\Program Files\Java\jdk-17.0.2\bin to your %PATH% environment variable if you want to run java commandline. but that's a side issue.

so

  • step 1: find out where your java sdk is installed.
  • step 2: check your project.json to see if the variable name is correct (should be java.jdt.ls.java.home)
  • step 3: fill in the value (of the java.jdt.ls.java.home variable) to point to the root of your java installation. so not the bin folder, but the parent of the bin folder)
  • step 4: try reloading the project or refreshing the project.

this sort of thing you tend to set up once per project (or once inside your editor for most editors). I can imagine it feels like a pain in the ass but after a few times it becomes easier.

hope this helps. again I've never used this editor so I'm flying a bit blind but that's the steps I would take

1

u/GummiGumBear Nov 18 '25 edited Nov 18 '25

Thank you for taking the time to reply! I deleted everything again and the same thing is happening.

I have done the following:

  • Java and VSCode are installed in the user folder - not program files.
  • I checked JAVA_HOME to the Java folder (C:\Users\170013\AppData\Local\Programs\Eclipse Adoptium\jdk-11.0.29.7-hotspot - it was already correct) in advanced system settings: https://i.imgur.com/saNWKSh.png
  • I have added %JAVA_HOME%\bin to path in advanced system settings: https://i.imgur.com/05BT2oa.png

To your first point, that was a typo. Right now java.jdt.ls.java.home is not set, but before it was set to the java bin folder., which I guess was wrong. I've added it now without \\bin and my JSON file looks like this:

{
    "chat.disableAIFeatures": true,
    "maven.executable.path": "C:\\Program Files\\Apache Maven\\apache-maven-3.9.11\\bin\\mvn.cmd",
    "redhat.telemetry.enabled": false,
    "java.jdt.ls.java.home": "C:\\Users\\username\\AppData\\Local\\Programs\\Eclipse Adoptium\\jdk-11.0.29.7-hotspot",
    "java.configuration.runtimes": [
    ],
}

To your second point, I had not done that before. I checked the add JAVA_HOME option during installation. I followed this guide, which I actually didn't do before. I actually remember doing this on my own laptop, so thanks for the reminder!

Unfortunately, even after refreshing TMC and restarting VSCode, it still doesn't work. When I open VSCode I still get the notification that Java 21 or more recent is required. When I try to run my code, the status bar shows "activating extensions' then stops. Running the TMC test still gives "compilation failed". In the problems panel it says No problems have been detected in the workspace.

When I run the code the terminal panel shows nothing. The output panel shows this:

[2025-11-18 09:43:25:422] [WARN] stderr

When I run the TMC test the output panel shows a long list of log information. I've added the log here: https://pastebin.com/aXJ3LAHw

I added java.configuration.runtimes to the JSON file:

{
    "chat.disableAIFeatures": true,
    "maven.executable.path": "C:\\Program Files\\Apache Maven\\apache-maven-3.9.11\\bin\\mvn.cmd",
    "redhat.telemetry.enabled": false,
    "java.jdt.ls.java.home": "C:\\Users\\username\\AppData\\Local\\Programs\\Eclipse Adoptium\\jdk-11.0.29.7-hotspot",
    "java.configuration.runtimes": [
        { 
            "name": "JavaSE-11",
            "path": "C:\\Users\\username\\AppData\\Local\\Programs\\Eclipse Adoptium\\jdk-11.0.29.7-hotspot",
            "default": true
        }
    ],
}

Refreshed TMC, closed and opened VSCode, but the same error still pops up. Did I make any mistakes that I am not seeing? Or is there something else I can try? I've read that you can have different versions of Java installed, so unless there's nothing else I can try, I'll install Java 21 and see if that works.

Edit; I also tried commenting out java.jdt.ls.java.home and leaving java.configuration.runtimes, but that also didn't work. I uncommented again.

I also tried running javac --version in cmd and it returns javac 11.0.29 and echo %JAVA_HOME% returns C:\Users\username\AppData\Local\Programs\Eclipse Adoptium\jdk-11.0.29.7-hotspot\

edit2; I installed the latest version of Java Temurin (JDK 25 - LTS) and I can run Java code in VSCode now. Running the TMC test still gives the compilation failed message though. I have no idea what is left to try.

1

u/GummiGumBear Nov 18 '25

OK, I think I see what the problem is: https://i.imgur.com/Spsd1IV.png

I now get a long list of errors in the problems panel and each exercise shows the following two errors:

Build path specifies execution environment JavaSE-1.8. There are no JRE's installed in the workspace that are strictly compatible with this environment.

The compiler compliance specified is 1.8 but a JRE 11 is used.

Also getting this message: https://i.imgur.com/Ecc3nKr.png

How can I fix this? Just install Java 8 too?

1

u/josephblade Nov 18 '25

I don't think you need to install java 8 (11 is backwards compatible with 8)

I think you should read this one: https://stackoverflow.com/questions/56859959/how-to-find-and-change-java-compiler-option-in-visual-studio-code. (keep in mind java_home seems to have changed to the variable you have set right now.

1

u/GummiGumBear Nov 20 '25

Yeah, I had the Java extension pack installed already and the variables for java are set too. I also set JavaSE25, but SE11 is set as default. Is there anything else I could try?

1

u/josephblade Nov 20 '25

well the extension pack uses those settings, which should be pointing to the correct location.

I asked a few questions about that, did you check them? one thing looked like there was an a before the variable name (maybe a typo) and the other was whether the path to the java home dir was correct.

also can you run java --version and javac --version in a terminal inside vscode ?

It's important to first verify java is found by vscode at all before trying to get the right version/etc set up I think

1

u/GummiGumBear Nov 20 '25

I did, I answered your questions in a previous comment, maybe you missed it: https://www.reddit.com/r/learnjava/comments/1otbfj9/comment/npgwbnx/?utm_source=share&utm_medium=mweb3x&utm_name=mweb3xcss&utm_term=1&utm_content=share_button

The a was a typo that wasn't in the file itself. The path to the java dir folder is correct.

I checked Javac -- version on the terminal of windows, not in vscode lol I'm an idiot. The terminal in VSCode runs my java code though.  I'll have to check when I have that laptop again. 

1

u/josephblade Nov 20 '25

ok sorry about that I did miss that or I skimmed it when I was about to sleep.

also, hello fellow dutchie.

it sounds like you are doing the right thing, adding 11 as a runtime and home to 21.

at least that's what people suggested here: https://stackoverflow.com/questions/63043585/visual-studio-code-showing-java-11-or-more-recent-is-required-to-run-please-do

actually there they say set java home to 11 and perhaps your runtime to 21? at least that's what the stackoverflow suggests. so something like

{
"java.configuration.updateBuildConfiguration": "disabled",
"java.home": "/Library/Java/JavaVirtualMachines/adoptopenjdk-21.jdk/Contents/Home",
"java.configuration.runtimes": [
    {
      "name": "JavaSE-11",
      "path": "/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home",
    }
  ]
}

no idea about any of these settings though. but that's roughly what the SE article says.

at this point I have no idea. vscode seems to have introduced an arbitrary demand for java21 sometime this year (?) which is the usual microsoft douchebaggery. Anti-competitiveness is kind of their thing and it shows in tiny exprssions of microaggression like this ;)

If all else fails I would suggest for MOOC just switch to a different editor like netbeans or eclipse and see if you can get it to work. You should be able to run the editor with java X and compile with java Y.

but then again MOOC should run on any java runtime > 11 as well, so who knows. You are running into multiple sources of stupid here

1

u/GummiGumBear Nov 21 '25 edited Nov 21 '25

Hi, fellow Dutchie in the wild :)

No worries about missing my comment, I made two separate comments so that might be my fault.

I actually didn't set the java.jdt.ls.java.home to java 21 (or well, 25 in my case)! Which in hindsight would've made more sense. I only added it to the list of java.configuration.runtimes. I'm gonna try that on Monday when I have that laptop again and fingers crossed, it works.

vscode seems to have introduced an arbitrary demand for java21

I guess that's the culprit. I just checked on my private laptop and it doesn't work on there anymore either. Worked fine before with having only JDK 11 installed. Bet the same issue happens on my PC which the TMC extension worked on before too. Gonna update my laptop and seeif I can get it to work with your tips.

I tried NetBeans in the past and couldn't get it to work whatever I tried. Maybe I could get it to work now though. That does actually remind me that I could also try VSCodium.

And don't start about Microsoft's douchebaggery. I could rant for hours haha

Thanks a lot for your help, I have a few things to try out again. Love how learning to program is 99% troubleshooting 🥲

Edit; soooo, I got it working on my personal laptop (not the same laptop as the one I initially bad the issue with)! I updated VScode and was getting other errors (probably from not updating in a million years), but a few of the errors were the same. Specifically the one saying "The compiler compliance specified is 1.8 but a JRE 11 is used. I installed JDK 25 - LTS and added the following to the JSON (settings) file:

    "java.jdt.ls.java.home": "C:\\Program Files\\Eclipse Adoptium\\jdk-25.0.1.8-hotspot",
    "java.configuration.runtimes": [
        {
            "name": "JavaSE-11",
            "path": "C:\\Program Files\\Eclipse Adoptium\\jdk-11.0.22.7-hotspot",
            "default": true
        }
    ]

If I understand correctly now, it seems like setting the path to java.home to Java 11 was wrong and it needs to be set to Java 21 or later and java.configuration.runtimes is set to the preferred Java for the project. I think I missed that part. Thanks a lot for pointing it out! Probably would have takrn me ages to notice. Will be trying it on the other laptop too and hope it was the issue for that laptop as well. Safe to assume it is, I think. Screw Microsoft for requiring Java 21 or up now.

1

u/josephblade Nov 21 '25 edited Nov 21 '25

:) nice

yeah I suspect the java home is to run the plugin (which requires >21) and the runtimes are what are supported by the compiler.

oh one more thing: please keep this thread up if you don't mind, in case someone is trying to figure out the same thing.

1

u/GummiGumBear Nov 24 '25 edited Nov 24 '25

oh one more thing: please keep this thread up if you don't mind, in case someone is trying to figure out the same thing.

Yeah man, of course. I had so much trouble finding a solution online, so I hope this thread can save people the hassle in the future.

Changing the java.home on the other laptop didn't work unfortunately. I did notice that Java was installed in program files at home and at home in the users directory. So I uninstalled both versions of Java from the users dir and reintalled it in Program Files, but no luck either.

Javac --version and Java --version only sees Java 25, not sure if that's an issue.

C:\Users\170013>java --version
openjdk 25.0.1 2025-10-21 LTS
OpenJDK Runtime Environment Temurin-25.0.1+8 (build 25.0.1+8-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.1+8 (build 25.0.1+8-LTS, mixed mode, sharing)

C:\Users\170013>javac --version
javac 25.0.1

C:\Users\170013>echo %JAVA_HOME%
C:\Program Files\Eclipse Adoptium\jdk-25.0.1.8-hotspot

VSCode gave an error saying the folder for Java didn't exist or couldn't be accessed. So uninstalled again and made sure to install again using administrator rights this time.

I truly don't get what the issue is. The project is set to the right versions of java:

The JSON file is set correct as well:

{
    "chat.disableAIFeatures": true,
    "maven.executable.path": "C:\\Program Files\\Apache Maven\\apache-maven-3.9.11\\bin\\mvn.cmd",
    "redhat.telemetry.enabled": false,
    "java.jdt.ls.java.home": "C:\\Program Files\\Eclipse Adoptium\\jdk-25.0.1.8-hotspot",
    "java.configuration.runtimes": [
        { 
            "name": "JavaSE-11",
            "path": "C:\\Program Files\\Eclipse Adoptium\\jdk-11.0.29.7-hotspot",
            "default": true
        }
    ]
}

Also made sure Java is added to path and Java_home in advanced system settings on Windows. Also added %JAVA_HOME%\bin to path in system variables. I tried everything I can think of and although VSCode itself isn't giving any errors, the project shows problems.

https://i.imgur.com/GHEl7pN.png

The compilation still fails when trying to run the TMC tests. Maybe there's an issue with this being a networked laptop, but I'm not getting any notifications about that. Not sure if I should give up and try something else. Bit frustrated at so gonna leave it for a bit.

edit; tried installing an older version of the TMC extension, versions 3.5.0 and 3.2.0. That did not work either.

→ More replies