0

After updating Java 8 (update 281) yesterday (2021-02-15) I could no longer use the Single-File Launch in the Windows Command Line. Prior to this I had no problems using this feature but now I get the following error;

Error: could not find or load main class filename.java

What did this update change or mess up? I'm very fond of the Single-File Launch feature and I would be very sad to never be able to run java files like this again. What can I do to fix this, any suggestions?

Details: I'm using the standard Windows 10 command line (cmd.exe). I have not updated the PATH variables because I don't know what to change to be honest, it worked before. Here's what I currently have in there that is relevant to Java; C:\Program Files (x86)\Common Files\Oracle\Java\javapath C:\Program Files\Java\jdk-13.0.1\bin

2
  • 1
    What the exact command line you are using? Did you update the Java related environment variables when you updated? Please edit the question and do not reply in the comments.
    – DavidPostill
    Feb 16, 2021 at 18:11
  • According to your link, single file launch was delivered in Java 11 so if you have replaced the default Java to version 8 then launch from .java file will stop working.
    – DuncG
    Feb 16, 2021 at 23:08

2 Answers 2

2

It looks like you have Oracle javapath (which is probably picking Java8) before Java13 binaries which would stop the single file/compile launch working as java xyz.java.

See @DrMoishe Pippik answer for helpful info editing the path, you could try swapping the order of these directories so that Java13 is first - if that directory exists:

C:\Program Files\Java\jdk-13.0.1\bin
C:\Program Files (x86)\Common Files\Oracle\Java\javapath

But note: this may lead to a secondary issue because other apps may fail if they depend on the Java8 installation over the Java13. Confirm which default is used in CMD.EXE with:

java -version

If you want multiple JDK and have need for CMD.EXE which prefers specific JDK version you can add shortcuts to desktop with following commands:

%COMSPEC% /V /K C:\somepathtoyourbin\java8.cmd

%COMSPEC% /V /K C:\somepathtoyourbin\java13.cmd

... and add files to set the preferred JAVAHOME in java8.cmd or java13.cmd. Example java13.cmd might be:

@echo off
set "JAVAHOME=C:\Program Files\Java\jdk-13.0.1"
set "PATH=%JAVAHOME%\bin;%PATH%"
1

Likely, the environment variable(s) for the path to java.exe need to be updated. First, check where java.exe and/or javaw.exe are in your PC file system. Then, open a CMD prompt, and type

echo %java_home%

or

where java

If that path is incorrect because of the update, the easiest way to correct it in Windows is with the Environment Variable editor.

  • Press Windows, type envi and select Edit the system environment variables [You must be an Administrator to do this.].
  • Select any variable with a java path that is incorrect and edit it.
  • Press Windows, type envi and select Edit environment variables for your account.
  • Select any variable with a java path that is incorrect and edit it.

You may need to reboot for the changes to take effect.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .